1
votes

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

Not rotating

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

3
Did you find a solution? It's good to follow up with comments / answers so future visitors know what did and didn't work for you. - BadFeelingAboutThis

3 Answers

0
votes

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

0
votes

In the function that implements your code.

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

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;
}