Created
September 2, 2011 00:48
-
-
Save thanksmister/1187691 to your computer and use it in GitHub Desktop.
Scale BitmapData Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected static function scaleImage(bitmapData:BitmapData, width:Number, height:Number):BitmapData | |
{ | |
// Calculate the scaled size. | |
var scale:Number; | |
var scaledWidth:Number; | |
var scaledHeight:Number; | |
scale = Math.min(width/(bitmapData.width as Number), height/(bitmapData.height as Number)) | |
scaledHeight = bitmapData.height * scale; | |
scaledWidth = bitmapData.width * scale; | |
var scalingMatrix:Matrix = new Matrix(); | |
scalingMatrix.scale(scale, scale); | |
// Scale the image. | |
var scaledImage:BitmapData = new BitmapData(scaledWidth, scaledHeight, true, 0x00000000); | |
scaledImage.draw(bitmapData, scalingMatrix, null, null, null, true); | |
bitmapData.dispose(); | |
return scaledImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment