Flex 3 - Saving a Component Image
I am currently trying to work with the imageSnapshot function in flex. I've been looking hard, but I can't seem to find a solution to my problem. I want to take a screenshot of one of my components to capture the final output of my program, since a simple "printscreen" disables part of the output due to scrolling. My current code looks like
<mx:ApplicationControlBar dock="true">
<mx:Button label="Take snapshot of Profile"
click="takeSnapshot();" />
</mx:ApplicationControlBar>
What when called does -
private function takeSnapshot(even:Event=null):void {
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(viewstack1);
Now I think this is taking the viewport image that I want ... But I was shocked at what to do from here! Is it not possible right now to just copy the image to the clipboard or create a new window in my browser with the entire image inside? If anyone has any other way to do this, suggestions would be great.
Thank you for your time.
I have built a working component (with full code) using Antti example, which you can view here here . You can print almost any component you like (I have an image and a datatum).
All you need to add to your Antti code is:
var fr:FileReference = new FileReference();
var encoder:PNGEncoder = new PNGEncoder();
//Antti code here
fr.save(outputData,"datagrid.jpg");
This will open a file save dialog for you.
Cheers, Casp
source to share
You can draw the view object to a BitmapData object and encode it to png using as3corelib . Something like:
var screenshotData : BitmapData = new BitmapData(viewstack1.width, viewstack1.height, true, 0x00000000);
screenshotData.draw(viewstack1);
var outputData:ByteArray = PNGEncoder.encode(screenshotData);
// Save outputData as a file to disk, send to webserver etc..
edit: Oh, that probably confuses you even more. Sorry about that. ImageSnapshot has a property called data, which I am guessing gives you almost the same result as this one. You can save it as a file to disk using flash.net.FileReference
source to share