android convert from rgb to hsv and viceversa
Finally I found the solution.
There seems to be a strange approximation in the android implementation of android.graphics.Color.RGBToHSV
.
The approximated value is exactly the Hue that in this implementation goes from 0° to 360°.
I found the code of java.awt.Color.RGBtoHSB where the HUE goes from 0.0f to 1.0f and the conversion works well. So is not a float precision bug but an implementation bug, infact by multipling the Hue * 360f
I get the correct HSV Hue value.
If someone looking around the conversion from RGB to HSV and vice versa in Kotlin language:
// define array and color
var hsv = FloatArray(3)
var currentColor = Color.rgb(206, 43, 55);
// RGB to HSV
Color.colorToHSV(currentColor, hsv)
// hsv[0] --> hue
// hsv[1] --> saturation
// hsv[2] --> value
// HSV to RGB
currentColor = Color.HSVToColor(hsv)
// assign red, green and blue
r = Color.red(currentColor)
g = Color.green(currentColor)
b = Color.blue(currentColor)