简体   繁体   中英

Flash/AS3 - MovieClip into Bitmap

I need to turn a MovieClip that I have on the stage into a Bitmap. The function I have made for this halfway works; it does make a Bitmap from the MovieClip with the correct image, but it does not rotate it.

Here is the function

    function makeBitmapData(mov):BitmapData
{
    var bmpData:BitmapData = new BitmapData(mov.width, mov.height, true, 0);
    bmpData.draw(mov);
    this.addChild(new Bitmap(bmpData)); //Shows the bitmap on screen purely for example
    return bmpData;
}

Here is the output

不旋转

How should I rotate the bitmap or just purely copy all the pixels in that bitmap, rotated and all?

Have you checked rotate() function and fl.motion.MatrixTransformer class? Also this question looks helpful.

In the function that implements your code.

    var b:Bitmap = new Bitmap (  makeBitmapData(mov) );
    addChild(b);
    b.rotation = mov.rotation;

One way to accomplish this, is to draw from the items parent instead, that way any transformation/filters will be reflected in the bitmap data captured. So something like this:

function makeBitmapData(mov:DisplayObject):BitmapData
{
    var rect:Rectangle = mov.getBounds(mov.parent); //get the bounds of the item relative to it's parent
    var bmpData:BitmapData = new BitmapData(rect.width, rect.height, false, 0xFF0000);
    //you have to pass a matrix so you only draw the part of the parent that contains the child.
    bmpData.draw(mov.parent, new Matrix(1,0,0,1,-rect.x,-rect.y));
    addChild(new Bitmap(bmpData)); //Shows the bitmap on screen purely for example
    return bmpData;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM