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/2d78ad53630bb25563ab28da6c9a3968.swf</mx:source>
                </mx:SWFLoader>
                <mx:SWFLoader x="60" y="53">
                
<mx:source>http://media.dev.freakatars.com.s3.amazonaws.com/2/0/5a97b1888731df7c766a4e274d766b20.swf</mx:source>
                </mx:SWFLoader>
                <mx:SWFLoader x="122" y="76">
                
<mx:source>http://media.dev.freakatars.com.s3.amazonaws.com/2/0/605299b92bc3993319ceb9490eb52b0f.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>



Reply via email to