Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert RGB to float values?

Tags:

c#

.net

colors

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

like image 302
GibEinenNamenEin Avatar asked Dec 07 '18 18:12

GibEinenNamenEin


People also ask

How do you convert RGB to Lab formula?

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.

How do you convert RGB to integer?

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);

Why is RGB 0 to 255?

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.

Why is RGB 255 and not 256?

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.


1 Answers

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.

like image 185
NetMage Avatar answered Sep 28 '22 18:09

NetMage