如何缩放位图数据 AS3



我正在为客户编辑一个空气应用程序,他希望您导入的图像在使用以下代码保存时缩放到 650x650。我尝试更改值,但是当导出图像时,缺少某些部分:

function menuItemClick1(event:Event):void{
    var mat:Matrix = new Matrix();
    mat.scale(2.0,2.0);
    var bmpData:BitmapData = new BitmapData(this.template_mc.width * 2, this.template_mc.height * 2, false, 0xFFFFFF);
    bmpData.draw(this.template_mc, mat);
    var _bmp:Bitmap = new Bitmap(bmpData);
    _bmp.smoothing = true;
    //
    imgBytes = PNGEncoder.encode(_bmp.bitmapData);
    fs = new FileStream();
    targetFile = File.desktopDirectory.resolvePath("icons/image.png");
    targetFile.browseForSave("Save Your File");
    targetFile.addEventListener(Event.SELECT, onSaveSelect);
}

我尝试更改为这个没有运气:

mat.scale(1.0,1.0);
var bmpData:BitmapData = new BitmapData(650,650, false, 0xFFFFFF);

以这种方式计算矩阵比例:

var mat:Matrix = new Matrix();
var ratio:Number =Math.min(650/this.template_mc.width,650/this.template_mc.height);
mat.scale(ratio,ratio);
var bmpData:BitmapData = new BitmapData(650, 650, false, 0xFFFFFF);
bmpData.draw(this.template_mc, mat);