调整BitmapData对象大小的最佳方法是什么?

Iai*_*ain 36 flash resize image actionscript-3 bitmapdata

假设我有一个600x600的BitmapData,我想将其缩小到100x100.

Iai*_*ain 69

这有效:

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);
Run Code Online (Sandbox Code Playgroud)

  • 这个`0x000000`非常重要,没有它就没有透明度 (2认同)

Car*_*rlo 19

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);
}
Run Code Online (Sandbox Code Playgroud)

IBitmapDrawable是DisplayObject和BitmapData的接口.

来自:http://www.nightdrops.com/2009/02/quick-reference-drawing-a-scaled-object-in-actionscript/


小智 10

平滑:

function BitmapScaled(source:IBitmapDrawable, thumbWidth:Number, thumbHeight:Number):BitmapData {
    var mat:Matrix = new Matrix();
    mat.scale(thumbWidth/source.width, thumbHeight/source.height);
    var bmpd_draw:BitmapData = new BitmapData(thumbWidth, thumbHeight, false);
    bmpd_draw.draw(source, mat, null, null, null, true);
    return bmpd_draw;
}
Run Code Online (Sandbox Code Playgroud)

draw方法接受IBitmapDrawable,它是DisplayObject和BitmapData的接口.