0
votes

How can I rotate an Image eg. 180 degrees clockwise using the Matrix

I can use the following code to rotate the image 90 degrees, but it is incremental, meaing

var matrix:Matrix = new Matrix();

matrix.rotate(Math.PI/2);
matrix.tx = imgControl.content.height;

var bitmapData:BitmapData = new BitmapData(imgControl.content.height, imgControl.content.width);
bitmapData.draw(imgControl.content, matrix);
imgControl.source = new Bitmap( bitmapData);

Each time I run the code the image is rotated +90 degrees.

What I want is not to increment by 90 each time, but explicit say rotate 180, rotate90 and so on.

I am not familiar with the Matrix, but I guess it does real bitmapdata manipulation rather than just eg. rotate the Image component box (arrest me if I am wrong).

If so, I guess I have to reset the image each time I do the rotate command.

Am I missing something?

Thanks in advance for any advice and tips

Ran

1

1 Answers

1
votes

The matrix does no real bitmapdata manipulation.

It is the bitmap.draw call that draws the rotated image of the imgcontrol.content into the bitmap, after which your code overwrites imgcontrol.content with the rotated image.

So as your code is currently standing, yes, you either have to refresh the image from scratch before every rotation, or you will have to keep track of the rotations in a variable and calculate how many more times you have to rotate to get to the desired rotation.

If you need to do multiple 90 degrees rotation in one step, then replace

matrix.rotate(Math.PI/2);

with

matrix.rotate(Math.PI/2 * howmanytimesyouwanttorotateby90degrees);