I have camera input app in flash (AS3) and I draw some graphics over it. I want to take the image snapshot of the stage visible area but only the video an graphics I draw over video. I want to exclude controls from the image snapshot. My display object layout is in following relation:
-stage
--canvas (Sprite)
---video (Video)
---overlayed graphics (Sprites, MCs, Shapes)
--controls (Buttons)
Stage size is fixed and I want to take a image snapshot of everything that is child of my canvas element (camera input video and overlayed graphics, but excluding controls). I am able to make this image snapshot when overlayed graphics are inside the bounds of stage size. I do it like this:
var bmpd:BitmapData = new BitmapData(canvas.width, canvas.height);
bmpd.draw(canvas, new Matrix(1, 0, 0, 1, canvas.x, canvas.y));
But this gives me unwanted result when graphics which I draw on top of video on canvas exceed the bounds of stage display area. How do I limit the image snapshot only in the bounds of visible area inside stage?
Thanks
what i've done in the past is use the as3corelib, which contains encoder classes for both JPG (JPGEncoder.as) and PNG (PNGEncoder.as) image files. these classes makes it quite effortless to create image files from your display objects.
here's the code from one of my programs which saves a .png of my entire stage and all of it's children to the local disk using FileReference.
//Save Canvas Snapshot
private function saveCanvasSnapshot():void
{
var bitmapData:BitmapData = new BitmapData(DropSwatch.controller.stage.stageWidth, DropSwatch.controller.stage.stageHeight);
bitmapData.draw(DropSwatch.controller);
var file:ByteArray = PNGEncoder.encode(bitmapData);
var fileReference:FileReference = new FileReference();
fileReference.save(file, "DropSwatchCanvas.png");
}
in your case, since you want all of your layers except for the controls, you could simply make the controls layer invisible while drawing the biamapData and make them reappear afterwards. then encode your bitmapData using PNGEncoder (or JPGEncoder), assign it to a ByteArray and save the byteArray as an .png (or .jpg)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With