0
我想將RGB像素顏色轉換爲HSV。我成功地修改了位圖的紅色,綠色和藍色。如何將這3個值轉換爲HSV值?如何將RGB轉換爲HSV?
詳細的我的代碼(retrive RGB顏色):
public View.OnTouchListener ivOnTouchListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Drawable imgDrawable = ((ImageView) iv).getDrawable();
Bitmap bitmap = ((BitmapDrawable) imgDrawable).getBitmap();
int coord_x = 0;
int coord_y = 0;
while (coord_x <= 1) {
while (coord_y <= 1) {
int touchedRGB = bitmap.getPixel(coord_x, coord_y);
int colorRed = Color.red(touchedRGB);
int colorGreen = Color.green(touchedRGB);
int colorBlue = Color.blue(touchedRGB);
float[] hsv = new float[3];
/*IT'S WORK, I GET THE RGB COLORS -> colorRGB.append(" || " + "In x: " + coord_x + "and y: " + coord_y + " --> RED: " + colorRed + " GREEN: " + colorGreen + " BLUE: " + colorBlue + " || ");
coord_y++;*/
Color.RGBToHSV(colorRed, colorGreen, colorBlue, hsv);
colorRGB.setText("THE NEW COLOR");
colorRGB.setTextColor(hsv);
}
coord_y = 0;
coord_x++;
}
return true;
}
};
我想目前的TextView的文本設置爲HSV,但我的程序已經崩潰。我該怎麼辦?