To flip an image around the center i am using this piece of code:
// Calculate offset
var offsetWidth:Number = image.contentWidth/2.0;
var offsetHeight:Number = image.contentHeight/2.0;
// Perform flip
var matrix:Matrix = new Matrix();
matrix.translate(-offsetWidth, -offsetHeight);
if(direction=="HORIZONTAL"){
matrix.scale(-1, 1);
}else if(direction=="VERTICAL"){
matrix.scale(1,-1)
}
matrix.translate(+offsetWidth, +offsetHeight);
matrix.concat(image.transform.matrix);
image.transform.matrix = matrix.clone();
which works fine.But my problem is when i try to get the BitmapData from the image like this:
var bitmapData:BitmapData = new BitmapData(image.width,image.height);
bitmapData.draw(image);
and use the bitmapData as source for another image,no image is displayed.Broken image icon appears.
Also i am rotating the image around center and using similar code as mentioned below and its working fine and i am able to copy the bitmapdata to another image..here’s the code for reference:
var matrix:Matrix = new Matrix();
matrix.rotate(Math.PI/2);
matrix.tx = img.content.height;
var bd:BitmapData = new BitmapData(img.content.height, img.content.width);
bd.draw(img.content, matrix);
Please help regarding the same.
Answer is in the question.
In the second case you are using matrix
Similarly do for the flip
EDIT:
Calculation of the translation for the matrix in flipping is not correct. Both the translation on X and Y are needed only when you flip horizontally and vertically.
Please find the code below in which it is working.