How do I convert RGB to float values?
17,566
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.
Author by
GibEinenNamenEin
Updated on June 27, 2022Comments
-
GibEinenNamenEin almost 2 years
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
-
GibEinenNamenEin over 5 yearswhat is iR? Is it the int?
-
NetMage over 5 years@RarePotato8DE Yes that is the
int
R value. -
Didi Kohen over 3 yearsWhy is it 255 and not 256? Aren't there 256 possible values for each color?
-
NetMage over 3 years@DidiKohen Yes, but the range of values is
0
to255
. You want to match those values to the range0.0
-1.0
, you want0
to return0
and you want255
to return1.0
.