Hi Guys,

I'm having some problems with getting the brightness of a color returned
from get pixel. get pixel returns an RGB color as a number which means I was
expecting something like three groups of three numbers 255 255 255 or
similar. what I am actually getting back is of this form 14540754 one digit
short.

If I do this

trace('hexidecimal value:'+myBitmapData.getPixel(t, h).toString(16));
trace('RGB value:'+myBitmapData.getPixel(t, h));

the result with toString(16) does return a valid looking hex like 5e6261

RGB value:8225152
hexidecimal value:5e6261

quite confusing.

What I would really like to do is use something like this to convert RGB to
HSB


//colorModel converter RGB->HSB
//returns a hsb object
RGBtoHSB  = function(rgb){
var r = rgb.r
var g = rgb.g
var b = rgb.b
var hsb = new Object();
hsb.b = Math.max(Math.max(r,g),b);
var min = Math.min(Math.min(r,g),b);
hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - min)/hsb.b);
hsb.b = Math.round((hsb.b /255)*100);
hsb.h = 0;
if((r == g) && (g == b)){
hsb.h = 0;
} else if(r >= g && g >= b){
hsb.h = 60*(g-b)/(r-b);
} else if(g >= r && r >= b){
hsb.h = 60 + 60*(g-r)/(g-b);
} else if(g >= b && b >= r){
hsb.h = 120 + 60*(b-r)/(g-r);
} else if(b >= g && g >= r){
hsb.h = 180 + 60*(b-g)/(b-r);
} else if(b >= r && r >= g){
hsb.h = 240 + 60*(r-g)/(b-g);
} else if(r >= b && b >= g){
hsb.h = 300 + 60*(r-b)/(r-g);
} else{
hsb.h = 0;
}
hsb.h = Math.round(hsb.h);
return hsb;
}

so that I can just use the hsb.b property to get my relative brightness. If
anyone can shed a bit of light on this id really apprecaite it.

James
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to