PDA

View Full Version : Lighten / Darken uint-formatted colors



m90
April 1st, 2009, 10:33 AM
Hello!

Is there an easy way to multiply a color that is stored in an uint? Basically what I would like to do would be applying a colorTransform-Object (like ColorTransform(1.2,1.2,1.2,1,0,0,0,0))to the uint and get the new value in return, but it will not work. Will I have to convert it into RGB first or am I missing something here?

Thanks!

luiner
April 1st, 2009, 10:39 AM
you need to sut out each color separately
eg:
var color:uint = 234238;
var improvegreen:Number = 1.2;
var red:uint = color>>>16;
var green:uint = (color>>>8) & 0xFF;
var blue:uint = color & 0xFF;
green = (uint)(green *improvegreen);
if (green>0xFF){green = 0xFF;}
color = red<<16 + green<<8 + blue;

thats the easy way :P

m90
April 1st, 2009, 11:52 AM
Hello! I expected much more hassle when doing it manually, so thanks alot!