Convert RGB to HSV in Android

I want to get the ARGB values ​​from a pixel and convert to HSV, and then set the pixel with the new values.

I do not quite understand how to do this. Can anybody help me?

+4
source share
2 answers

Say you have a Bitmap object and the x and y coordinates. You can get the color from the bitmap as a 32-bit value like this:

int color = bitmap.getPixel(x, y);

You can highlight argb components as follows:

int a = Color.alpha(color);
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);

Then you can convert to HSV as follows:

float[] hsv = new float[3];
Color.RGBToHSV(r, g, b, hsv);

Now you can manipulate the HSV values, but you want to. When you are done, you can convert back to rgb:

color = Color.HSVToRGB(hsv);

or how is it you want to use the alpha value:

color = Color.HSVToRGB(a, hsv);

( ):

bitmap.setPixel(x, y, color);
+5

Android: public static void Color#RGBToHSV(int, int, int, float[])

RGB HSV hsv - 3, HSV. hsv[0] - Hue [0.. 360), hsv[1] - [0... 1], hsv[2] - [0... 1].

+2

All Articles