Skip to content

Instantly share code, notes, and snippets.

@thanksmister
Created September 2, 2011 00:48
Show Gist options
  • Save thanksmister/1187691 to your computer and use it in GitHub Desktop.
Save thanksmister/1187691 to your computer and use it in GitHub Desktop.
Scale BitmapData Method
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