Ben Bleything
8/10/2006 12:40:00 AM
On Thu, Aug 10, 2006, Bruno Malvestuto wrote:
> How i can convert hex to rgb?
Do you mean a hex color code like #ffccff to RGB values like:
R: 255
G: 204
B: 255
?
The first two characters of the hex color code are the red value, the
second pair the green, and the final pair the blue value. Grab those
three substrings, convert the hex to decimal, and you're golden.
"#ffccff".match /#(..)(..)(..)/
puts "R: #{m[1].hex}"
puts "G: #{m[2].hex}"
puts "B: #{m[3].hex}"
That's not going to work in all cases (for instance, it's legal to do
#fff if you mean #ffffff), but it should get you started :)
Ben