1

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?

foo bar
  • 75
  • 6

3 Answers3

0

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

Community
  • 1
  • 1
coner
  • 270
  • 7
  • 21
  • Thanks for suggesting that. I have now used the Matrix class, not the MatrixTransformer, because that is what the draw function calls for. However, now there is a new problem, when I rotate the bitmapData, it clips the edges of it off. So how do I stop it from clipping? – foo bar Jul 23 '15 at 15:02
  • Since the Flash uses rectangle as a main shape, rotated ones cropped at the points where edges and corners intersect. I am not sure but you may hold bitmap in a big rectangle container so it will appear in full scale. – coner Jul 23 '15 at 15:19
  • Consider making your answer more useful by providing examples, and not just suggestions and links - right now this is more suited to comments on the question than a real answer. – BadFeelingAboutThis Jul 23 '15 at 18:17
  • So do you mean if someone does not have enough rep to "comment to others posts", they should not help them? You are out of chronogical order of events. – coner Jul 24 '15 at 08:29
0

In the function that implements your code.

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

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;
}
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40