AS3 BitmapData CopyPixels with alpha

rorypicko picture rorypicko · Aug 29, 2012 · Viewed 7.2k times · Source

I am trying to copy the pixels of a bitmap into BitmapData at a transparency of lets say .5 but i can't seem to find any reference to this anywhere on google or here!

i have my standard copy pixel code

_bitmapData.copyPixels(_bitmaps.vault[BitmapNames.BITMAPNAME], SCREENRECT, _drawPoint, null, null, true);

I can see that the first null value i pass is a BitmapData labelled alphaBitmapData:BitmapData so i'm assuming it has something to do with that, but i cant work it out!

Any help would be appreciated, cheers!

Answer

Will Kru picture Will Kru · Aug 29, 2012

Following this link you will find some explanation about the variables.

In short, when you set the last parameter (mergeAlpha:Boolean) to true, the function will take the 4th parameter (alphaBitmap:BitmapData) into account when copying the pixels, effectively using the alpha of the alphaBitmap to merge the copied pixels. So you should pass the same bitmap you use for the first parameter to the 4th parameter, set the 5th parameter (alphaPoint:Point) accordingly and set the last parameter to true.