in reply to Color Converstion
On win32, a color is defined as a 24-bit number, bits 23 to 16 define B, bit 15 to 8 define G, and bit 7 to 0 define R. see this web page for details.
The formula you want is: (B * 256 + G) * 256 + R. You can wrap it in a sub.
use strict; use warnings; print rgb(255,255,255), "\n"; #this gives you 16777215 print sprintf("0x%x", rgb(255,255,255)), "\n"; print rgb(255,0,0), "\n"; print sprintf("0x%x", rgb(255,0,0)), "\n"; sub rgb { return ($_[2] * 256 + $_[1]) * 256 + $_[0]; }
|
|---|