Say I have a BitmapData of 600x600 and I want to scale it down to 100x100.
This works:
var scale:Number = 1.0/6.0;
var matrix:Matrix = new Matrix();
matrix.scale(scale, scale);
var smallBMD:BitmapData = new BitmapData(bigBMD.width * scale, bigBMD.height * scale, true, 0x000000);
smallBMD.draw(bigBMD, matrix, null, null, null, true);
var bitmap:Bitmap = new Bitmap(smallBMD, PixelSnapping.NEVER, true);
public function drawScaled(obj:IBitmapDrawable, thumbWidth:Number, thumbHeight:Number):Bitmap {
var m:Matrix = new Matrix();
m.scale(WIDTH / obj.width, HEIGHT / obj.height);
var bmp:BitmapData = new BitmapData(thumbWidth, thumbHeight, false);
bmp.draw(obj, m);
return new Bitmap(bmp);
}
IBitmapDrawable is an interface for DisplayObject and BitmapData.
from: http://www.nightdrops.com/2009/02/quick-reference-drawing-a-scaled-object-in-actionscript/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With