I want to use 3 bitmaps to create 1 resulting bitmap. The first will be the background. The second shall be drawn on top of the first with the help of a mask.
The images are loaded into Bitmap
/BitmapData
objects.
Example:
(red-green image is the mask, red is the visible part)
back mask source result
So how can I do that? What drawing function do I use in ActionScript-3?
Thanks for any help!
Edit:
(my first working solution, works only with pure red, green or blue)
var back: BitmapData = // load the back image
var mask: BitmapData = // load the mask image
var source:BitmapData = // load the source image (32-bit)
var result:BitmapData = back.clone();
// clone source because it will be modified in next step
var source2: BitmapData = source.clone();
// red of the mask becomes the alpha channel of source2
source2.copyChannel(mask, new Rectangle(0, 0, mask.width, mask.height), new Point(0, 0), BitmapDataChannel.RED, BitmapDataChannel.ALPHA);
// draw source2 to result
result.draw(source2);
(Is there a more efficient way? In this solution I have to clone source in order to keep original source bitmap intact.)