PDA

View Full Version : Get RGB values from Hexadecimal Color


ashwan
09-08-2007, 01:49 AM
Hello!

In JSFL is there way to get the R, G & B values from a hexadecimal value that is returned by fill.color?

I was trying this:

hex = fill.color;
var rVal = hex >> 16;
var temp = hex ^ rVal << 16;
var gVal = temp >> 8;
var bVal = temp ^ gVal << 8;

but getting a 0 for all the values!

Thanks
Ashwan.

ashwan
09-12-2007, 12:37 AM
If anyone needs to know this, you can get it by using this function:

Check this site:
http://ejohn.org/blog/numbers-hex-and-colors/

and use this function:

function toNumbers( str ){
var ret = [];
str.replace(/(..)/g, function(str){
ret.push( parseInt( str, 16 ) );
});
return ret;
}

Call the function like this:

toNumbers( "7DFF00" )

an array is returned.

Ashwan.