#ff0000 <-> 255,0,0

Blitz3D Forums/Blitz3D Programming/#ff0000 <-> 255,0,0

nazca(Posted 2003) [#1]
Can someone tell me how to convert a hex string (ie: #ff0000), which is used in html, to a RED, GREEN, and BLUE value?

thanks!


nazca(Posted 2003) [#2]
EDIT: a hex to integer converter would be fine :)


Gabriel(Posted 2003) [#3]
this?

http://www.blitzbasic.com/codearcs/codearcs.php?code=219


Red(Posted 2003) [#4]
TIP : color 0,0,$FF0000 <-> color $FF,$00,$00


Gabriel(Posted 2003) [#5]
TIP : color 0,0,$FF0000 <-> color $FF,$00,$00


True, but he only has to bitshift.


Sir Gak(Posted 2003) [#6]
Here is how you can break apart a hex color string into the individual RGB values
Graphics 640,480
hex_value=$ffaabbcc
Print Hex((hex_value And $FF0000) Shr 16)
Print Hex((hex_value And $FF00) Shr 8)
Print Hex(hex_value And $FF) 		
MouseWait()
End


In the above example, the first $ff is the alpha value. Then are listed the RGB values, $aa, $bb, $cc.

Since the Hex command converts numeric hex values into alphanumeric string values, in case you want to numerically alter the RGB values (something you cannot do to a string), then for actual usage, instead of Print..., do something like (leaving off the "Hex" command):
Graphics 640,480
hex_value=$ffaabbcc
my_red = ((hex_value And $FF0000) Shr 16)
my_green = ((hex_value And $FF00) Shr 8)
my_blue = (hex_value And $FF) 		
MouseWait()
End



nazca(Posted 2003) [#7]
thanks!