Bill
Bill

Reputation: 19338

as3 filp bitmap both vertical and horizontal

just a quick one i would like to flip the image both vertical and horizontal.

my code below is only doing me vertically anything not right?

var matrix:Matrix = new Matrix();
matrix.scale(1,-1);
matrix.translate(0,bitmapData.height);

var flipHorizontalMatrix:Matrix = new Matrix();
flipHorizontalMatrix.scale(-1,1);
flipHorizontalMatrix.translate(bitmapData.width,0);

bitmapData.draw(loaderInfo.loader, matrix);


var image:Bitmap = new Bitmap(bitmapData);
image.width = 1024;
image.height = 702;
Bitmap(image).smoothing = true;

Upvotes: 1

Views: 1621

Answers (2)

Bill
Bill

Reputation: 19338

If you would like to Matrix, the following code works. Just tested :)

var matrix:Matrix = new Matrix();
matrix.scale(1,-1);
matrix.scale(-1,1);
matrix.translate(0,bitmapData.height);
matrix.translate(bitmapData.width,0);

bitmapData.draw(loaderInfo.loader, matrix);


var image:Bitmap = new Bitmap(bitmapData);
image.width = 1024;
image.height = 702;
Bitmap(image).smoothing = true;

Upvotes: 2

Marty
Marty

Reputation: 39466

Why not try a simpler approach:

// Reverse the X and Y scale, flipping the image along both axis.
image.scaleX = image.scaleY = -1;

Upvotes: 3

Related Questions