Link to home
Start Free TrialLog in
Avatar of cubical38
cubical38

asked on

AS3 draw(); only a portion of the stage

From the code here, I need to be able to set the boundaries of the bitmapData that is being drawn and saved out to a different x and y position.  When the stage is being drawn it is drawn from stage's (0,0).  I need to draw from x:55 y:46.  I have tried to use a bitmap and add the bitmapData to it but then I get a blank white box (no bitmapData).  What do I need to do?
private function saveImage (e:MouseEvent):void {
			var myBitmapData:BitmapData = new BitmapData(694,385);
			//var bitmap:Bitmap= new Bitmap(myBitmapData);
			//addChild(bitmap);
			//bitmap.x = 55;
			//bitmap.y = 46;
			//myBitmapData.draw (bitmap);
                        myBitmapData.draw (stage);
			var jpgEncoder:JPGEncoder = new JPGEncoder(80);
			var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);
			file = new FileReference();
			file.save (imgByteData, "test.jpg");
		}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Antonio Estrada
Antonio Estrada
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cubical38
cubical38

ASKER

Here is the finished code:
var myBitmapData:BitmapData = new BitmapData(804,477);
                  var rect:Rectangle = new Rectangle(55,46,694,385);
                  var colorTrans:ColorTransform = new ColorTransform(1,1,1);
                  myBitmapData.draw (stage, new Matrix(), colorTrans, null, rect, false);

Thanks!
Glad to help!

-V