DisplayObject snapshot in flex 3

Posted by simplemagik on Stack Overflow See other posts from Stack Overflow or by simplemagik
Published on 2009-07-09T11:53:15Z Indexed on 2010/03/25 0:03 UTC
Read the original article Hit count: 310

Filed under:
|
|

i'm creating a visual editor in flex and need to let users export thier projects into Image format. But i have one problem: size of the canvas is fixed and when user add element which is out of these sizes some scroll bars added. And user continue working on the project. but when he want to take snapshot of the canvas he just get the visible part ot the canvas with scrollbars. how to get image of the fullsize canvas?

The only solution i found is to check the positions and sizes of canvas child objects and rezise it to fit them. then take snap and resize back. But it hmmmm... too complicated i think. Is there some "easy methods"?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
	<![CDATA[
		import mx.graphics.ImageSnapshot;

		private function SnapshotButtonHandler():void
		{
			var snapshot:ImageSnapshot = ImageSnapshot.captureImage(AppCanvas);
			var file:FileReference = new FileReference();
			file.save(snapshot.data, "canvas.png");
		}
	]]>
</mx:Script>
<mx:Canvas id="AppCanvas" width="800" height="300" backgroundColor="0xFFFFFF">
	<mx:Box x="750" y="100" width="100" height="100" backgroundColor="0xCCCCCC" />
</mx:Canvas>
<mx:Button id="SnapshotButton" label="take snapshot" click="SnapshotButtonHandler()" />	
</mx:Application>

© Stack Overflow or respective owner

Related posts about flex

Related posts about flash