Reputation: 35760
According to the document, android.graphics.Color has a method called RGBToHSV
which can convert RGB values to HSV, this is what the document tells me:
public static void RGBToHSV (int red, int green, int blue, float[] hsv)
Convert RGB components to HSV.
hsv[0]
is Hue [0 .. 360)hsv[1]
is Saturation [0...1]hsv[2]
is Value [0...1]Parameters
- red: red component value [0..255]
- green: green component value [0..255]
- blue: blue component value [0..255]
- hsv: 3 element array which holds the resulting HSV components.
But when I write a program to test it, it doesn't work any way.
float[] hsv = new float[3];
RGBToHSV(255, 255, 0, hsv);
Log.i("HSV_H", "" + hsv[0]); // always output 0.0
Is it a bug ?
Upvotes: 1
Views: 4786
Reputation: 11
The result for hsv[1], hsv [2] is a decimal number, so you have to multiply by 100 to get the percentage.
Upvotes: 1
Reputation: 11511
What are your expected values? To me it seems to be working.
The code I used:
float[] hsv = new float[3];
android.graphics.Color.RGBToHSV(255, 255, 0, hsv);
Log.i("HSV_H", "Hue=" + hsv[0]);
Log.i("HSV_H", "Saturation=" + hsv[1]);
Log.i("HSV_H", "Value=" + hsv[2]);
The results:
Hue=60.0
Saturation=1.0
Value=1.0
This was run using a project targeting Android SDK 1.6 (API level 4) on a 1.6 emulator.
Upvotes: 4
Reputation: 9212
There is no indication that RGBtoHSV is assigning any values to the hsv array; try something like this:
RGBtoHSV(255, 255, 0, hsv);
And then check the value of hsv[0].
Upvotes: 0