|
Posted by Jeckyl on 01/16/07 23:39
> The formula you gave before:
> var rgb : String = "0x" + ((r*256+g)*256+b).toString(16);
>
> Ahhh, I see where you failed, you forgot to mention that you needed to
> ADD the blue. So the formula should ACTUALLY be:
> (r * 65536)+(g * 256)+b
It was already correct .. I didn't fail to mention it .. you failed to read
it .. see your own quote from me above.
>> to convert 8-bit unsigned (0..255) R,G, and B values to an RGB value
>> you need to shift the red 16 bits and the green 8 bits to the left
> ...but what you don't say is WHY.
OK .. looks like its back to the very basics. I hope I don't need to go
back to explain binary numbers, bits, and bytes.
A color specifed as an RGB value needs 8 bits (1 byte) for each of the R, G
and B values (which are in the range 0 .. 255 inclusive). These are usually
stored as consecutive bytes, usually in blue, green, red order. You can
also treat those three lots of 8 bits as a single 24-bit number. The
formula given converts the three individual 8-bit values into a single
24-bit value.
I hope that explains it.
--
Jeckyl
Navigation:
[Reply to this message]
|