Flash: the function of mergeAlpha in copyPixels

the sytx of copyPixels is like this:
copyPixels(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [alphaBitmap:BitmapData], [alphaPoint:Point], [mergeAlpha:Boolean]) : Void

Just assume, we have a destination BMP called desBMP, a sourceBitmap, and a alphaBitmap to provide secondary alpha setting.

desBMP.copyPixels(sourceBitmap,sourceRect,destpoint,alphaBitmap,alphaPoint,mergeAlpha);

1. Things need to be clarified first


For desBMP, its transparency attribute is only defined when this BMP is created. it won’t be changed when the copy pixel happens.

2. How mergeAlpha works?


I search tons of help documents. It just said like
“mergeAlpha:Boolean (default = false) — To use the alpha channel, set the value to true. To copy pixels with no alpha channel, set the value to false. ”
There is no exmaple showing how this works and the effect of it.

After hundreds of tests, I got the following conclusions:

2.1 if you set mergeAlpha=true:

first, flash got a temp bmp which is created by copy pixel from souceBMP and using the alpha setting probided by alphaBitmap;

second, the temp bump will be blended with the original pixel on desBMP to create a new bmp.

It means your original pixel from desBMP also have difference to your final bmp;

2.2 when mergeAlpha=false;
The original pixel from desBMP will be erased and only copied pixel works. That means how the final bmp looks like is totally determined by the combination of sourceBitmap, alphaBitmap and their alpha setting.

Here is some conclusion I got:

when alphaBitmap’s transparency=false, the alpha of desBMP = the alpha of sourceBitmap
(it is working like without setting alphaBitmap)

when alphaBitmap’s transparency=true,the alpha of desBMP = the alpha of sourceBitmap x the alpha of alphaBitmap; if sourceBitmap doesn’t support transparent, its alpha=100(ff)

so there are some special cases the desBMP’s alpha=0, the image will be invisible;

A. sourceBitmap’s alpha=0;

B. alphaBitmap’s alpha=0;

C. both of them are 0;

Generally, the function of mergeAlpha is defined whether the pixels from desBMP works in the new bmp.
If you mergeAlpha=true, you will blend the copied pixel with your original pixels; if mergeAlpha=false, the original pixel will be erased and only copied pixel works.

Share this post:

Leave a Comment.