im getting 3 ints: R, G, B I want to use this colors for something where i need to enter 3 floats: R, G, B. How do I "convert" the int to a float? Because in the float 1 is the highest
Thanks
Description. lab = rgb2lab( RGB ) converts sRGB values to CIE 1976 L*a*b* values. lab = rgb2lab( RGB , Name,Value ) specifies additional conversion options, such as the color space of the RGB image, using one or more name-value pair arguments.
To set the values from RGB you can do so by: Color myColour = new Color(red, green, blue); int rgb = myColour. getRGB(); //Change the pixel at (x,y) ti rgb value image. setRGB(x, y, rgb);
In RGB, a color is defined as a mixture of pure red, green, and blue lights of various strengths. Each of the red, green and blue light levels is encoded as a number in the range 0.. 255, with 0 meaning zero light and 255 meaning maximum light.
Because the 24-bit code is divided into 8 bits for each color (R/G/B). There are a total of 256 numbers in the binary eight bits in the system, and the maximum value from 0 is 255.
Depending on the range of the int
RGB values, you can simply divide by the maximum brightness value allowed to convert to float
.
For example, if the int
ranges from 0 - 255 (e.g. HTML Color Codes), then you can use
float fR = intR / 255.0F;
and so on for G and B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With