Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to resize a BitmapData object?

Say I have a BitmapData of 600x600 and I want to scale it down to 100x100.

like image 709
Iain Avatar asked Jun 08 '09 11:06

Iain


2 Answers

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);
like image 131
Iain Avatar answered Oct 23 '22 10:10

Iain


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/

like image 32
Carlo Avatar answered Oct 23 '22 11:10

Carlo