Reputation: 600
I have a movieclip on stage. Its 500x400. It has many children of diffent sizes added to it. How can I capture the area 300x200 of the movieclip from (0,0). Suppose there was a child at (100,100) of width and height 300 then I should be able to see from this child from 100 to 300 and 100 to 200 respectively. The rest of the area is not needed. I should be able to manipulate the captured image later. So I guess I have to capture it as a Bitmap. But how can this thing be done.
Upvotes: 0
Views: 842
Reputation: 39458
var bd:BitmapData = new BitmapData(300, 200, true, 0);
bd.draw(your_movieclip);
var bitmap:Bitmap = new Bitmap(bd);
addChild(bitmap);
Or you could try using this quick class:
package
{
import flash.display.DisplayObject;
import flash.display.BitmapData;
import flash.display.Bitmap;
public class BitmapGrab extends Bitmap
{
/**
* Copies a section of a MovieClip and stores as BitmapData
* @param target The target DisplayObject to draw from
* @param wpx The area width
* @param hpx The area height
*/
public function copyGraphics(target:DisplayObject, wpx:uint, hpx:uint):void
{
bitmapData = new BitmapData(wpx, hpx, true, 0);
_bmd.draw(target);
}
}
}
To use:
var bmg:BitmapGrab = new BitmapGrab();
bmg.copyGraphics(your_movieclip, 300, 200);
addChild(bmg);
Upvotes: 3