Ok, using the @ansiart answer as a starting point, I was able to calculate the sizes this way:
public function getTransformedBitmapData(origin:BitmapData):BitmapData { var matrix:Matrix = new Matrix(); // ajusting the anchor point and rotating matrix.translate(-origin.width / 2, -origin.height / 2); matrix.rotate(Math.PI / 4); // 45 deg matrix.translate(origin.width / 2, origin.height / 2); // scaling matrix.scale(1.5, 1.5); // Finding the four corners of the bounfing box after transformation var topLeft:Point = matrix.transformPoint(new Point(0, 0)); var topRight:Point = matrix.transformPoint(new Point(origin.width, 0)); var bottomLeft:Point = matrix.transformPoint(new Point(0, origin.height)); var bottomRight:Point = matrix.transformPoint(new Point(origin.width, origin.height)); // Calculating "who" is "where" var top:Number = Math.min(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y); var bottom:Number = Math.max(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y); var left:Number = Math.min(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x); var right:Number = Math.max(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x); // Ajusting final position matrix.translate(-left, -top); // Calculating the size of the new BitmapData var width:Number = right - left; var height:Number = bottom - top; // Creating and drawing (with transformation) var result:BitmapData = new BitmapData(width, height, false, 0); result.draw(origin, matrix); return result; }
I think it might be a bit overkill, but it works.
source share