开发者

Capturing a part of a movieclip

开发者 https://www.devze.com 2023-03-04 15:24 出处:网络
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 w

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 fr开发者_开发知识库om 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.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号