haruka.k haruka.k - 3 months ago 11
ActionScript Question

Storing the result of blended images in AS3.0

I am making an interactive animation which background images are masked by a shape captured in a camera. In the every frames, camera changes images into black and white images and then it's used to mask background images.

In the code, "now" is the images captured by camera, "P1" is the back ground image.

After I masked by using blend mode multiply, I wish to store the result image which is masked and use for other things.
I don't understand when I use blendmode function, how the result is defined well.
Can I capture, copy or store the result image?

var P1:MovieClip = new p1();
var mskimg:MovieClip = new maskimage();

var bitmap_obj:Bitmap = new Bitmap(now);

addChild(P1);
P1.blendMode = BlendMode.LAYER;
addChild(bitmap_obj);
bitmap_obj.blendMode = BlendMode.MULTIPLY;


enter image description here

Answer

You can draw a masked object if you put everything that you intend to be drawn into a container, then call BitmapData.draw() to draw the complete layered object to some BitmapData. Then, you can use that bitmap data to do whatever you want, Graphics.beginBitmapFill(), FileReference.save(), whatever. The operation is however expensive, so it'll be better if you trigger the drawing by responding to a user action, and not do that every frame by default, unless required by your application's logic.