You may have to play with some of the positioning, but use the second
parameter of the bitmapData.draw() function to pass in the object's
transform matrix as a start. This should get you closer...

 

bitmapdata.draw( displayObject2, displayObject2.transform.matrix );

 

HTH,

Ryan

 

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Kyle
Sent: Tuesday, December 09, 2008 12:21 PM
To: [email protected]
Subject: [flexcoders] getBitmapData from a scaled display object

 


I'm trying to figure out the easiest way to get bitmapdata from a
displayobject that has had its scalex/scaley altered. In the test
example I have listed below, I have a canvas container that has 3
children (swfLoader components). I set the scalex/scaley of the canvas
container to 2 and its' children are scaled up proportionally;
however, when I try to get bitmapdata from the canvas, it does not
recognize the scaled size of the canvas container and as such when I
create a new bitmap using the data it is still at the original size.
Any ideas on how I can get bitmapdata that will match the width/height
of the scaled canvas would be greatly appreciated!

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" creationComplete="createImage()">

<mx:Script>
<![CDATA[
import mx.controls.SWFLoader;
import mx.utils.ObjectUtil;
import mx.graphics.codec.PNGEncoder;

var displayObject2:Canvas;

private function createImage():void
{ 
displayObject2 = new Canvas();
displayObject2.setStyle("backgroundColor","0xc0c0c0");
displayObject2.width = myCanvas.width;
displayObject2.height = myCanvas.height;
for( var x=0; x<myCanvas.numChildren; x++ )
{
var curChild:SWFLoader = myCanvas.getChildAt( x ) as SWFLoader;
var newChild:SWFLoader = new SWFLoader();
newChild.source = curChild.source;
newChild.x = curChild.x;
newChild.y = curChild.y;

displayObject2.addChild( newChild );
}

displayObject2.scaleX = displayObject2.scaleY = 2;
displayObject2.y = 300;
addChild( displayObject2 );
}

private function scaleChild( e:Event ):void
{
e.target.width = e.target.contentWidth * 2;
e.target.height = e.target.contentHeight * 2;
}

private function createBitmap( e:Event ):void
{
var w = displayObject2.width;
var h = displayObject2.height;
var bitmapdata:BitmapData = new BitmapData( w, h, true, 0x00C0C0C0 );
bitmapdata.draw( displayObject2 );

var bytearray:ByteArray;
var encoder:PNGEncoder = new PNGEncoder();
bytearray = encoder.encode( bitmapdata );
myImage.source = bytearray;
}
]]>
</mx:Script>
<mx:Canvas x="10" y="10" width="200" height="200"
backgroundColor="#FFFFFF" id="myCanvas">
<mx:SWFLoader x="10" y="30">

<mx:source>http://media.dev.freakatars.com.s3.amazonaws.com/2/0/2d78ad53
630bb25563ab28da6c9a3968.swf</mx:source>
</mx:SWFLoader>
<mx:SWFLoader x="60" y="53">

<mx:source>http://media.dev.freakatars.com.s3.amazonaws.com/2/0/5a97b188
8731df7c766a4e274d766b20.swf</mx:source>
</mx:SWFLoader>
<mx:SWFLoader x="122" y="76">

<mx:source>http://media.dev.freakatars.com.s3.amazonaws.com/2/0/605299b9
2bc3993319ceb9490eb52b0f.swf</mx:source>
</mx:SWFLoader>
</mx:Canvas>
<mx:Button x="119" y="218" label="Create PNG"
click="createBitmap(event);"/>
<mx:Image x="460" y="10" id="myImage"/>
</mx:Application>

 



This message is private and confidential. If you have received it in error, 
please notify the sender and remove it from your system.

Reply via email to