Flex 4 ~ save Group, Canvas content as image and download

MXML
--------------------------------------------------------------------------------------------------
<s:Group id="imageCav" x="0" y="30" width="300" height="200" clipAndEnableScrolling="true" >
<mx:Image id="PreviewImage" x="0" y="0" />
</s:Group>

<s:Button label="save Image" click="saveImage()" x="50" y="300">




Action Script
--------------------------------------------------------------------------------------------------

private function saveImage():void{
var bd:BitmapData = new BitmapData(imageCav.width,imageCav.height);
bd.draw(imageCav);
var ba:ByteArray = (new PNGEncoder()).encode(bd);
(new FileReference()).save(ba, "cool.png");
}




reference
http://www.jamesward.com/2009/04/16/flex-paint-2/

http://www.jamesward.com/demos/FlexPaint2/srcview/index.html

1 則留言:

nereocorp 說...

thanks, very usefull !!! Exporting documents ...