Thursday, April 27, 2006

Stripping The Alpha Channel From An ARGB Value

I ran into this problem when I was working on a project where I was holding one large set of ARGB data within flash. For those of you who don't know flash's non-base 10 number support is half-hearted at best. I kept wracking my mind on how to remove the alpha channel. I could break up the ARGB number into it's components: alpha, red, green, and blue. Once that's done simply take the red, green, and blue and make a RGB value out of them.

This worked great, however, it was extremely slow with many values in real time.
I knew that I was using bitwise operators to convert from hex to decimal so that got me thinking.
There must be a bitwise operator to do this easily and quickly.

After a little investigation I came uppon the bitwise AND operator. With this you can easily "mask" out the alpha channel using one simple line.

var alphaColour:Number = myBitmap.getPixel32( scope._xmouse, scope._ymouse );
var nonAlpha:Number = alphaColour & 0x00FFFFFF;


By using 0x00FFFFFF as the "mask" the bitwise AND operator only returns the red, green, and blue values from the ARGB value that was grabbed from the bitmap.

0 Comments:

Post a Comment

<< Home