用这个
public function onLoadComplete(event:Event):void{
logoFileInput.editable = true;
logoFileInput.text = logoFileRef.name;
logoFileInput.editable = false;
logoSelected = true;
var ldr:Loader = new Loader();
var ptr:* = null;
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{
var bm:Bitmap = new Bitmap(e.target.content.bitmapData);
bm.smoothing = true;
bm.scaleX = 100;
bm.scaleY = 100;
var ratio:Number = 0;
// bm.bitmapData.width/bm.bitmapData.height
if(bm.bitmapData.width > bm.bitmapData.height)
ratio = bm.bitmapData.width/bm.bitmapData.height;
else ratio = bm.bitmapData.height/ bm.bitmapData.width;
var h:int = bm.bitmapData.height;
var w:int = bm.bitmapData.width;
if(h > w){
h = 40;
w = 40 / ratio;
}else if(h < w){
w = 40;
h = 40/ratio;
}else{
h = 40;
w = h;
}
var scale:Number = 0 ;
//50/bm.bitmapData.width
if(bm.bitmapData.width > bm.bitmapData.height)
scale = 50/bm.bitmapData.width;
else scale = 50/bm.bitmapData.height;
var matrix:Matrix = new Matrix();
matrix.scale(scale, scale);
var smallBMD:BitmapData = null;
if(bm.bitmapData.width > bm.bitmapData.height)
smallBMD = new BitmapData(50, (50/ratio), true, 0x000000);
else smallBMD = new BitmapData((50/ratio), 50, true, 0x000000);
smallBMD.draw(bm, matrix, null, null, null, true);
var x:PNGEncoder = new PNGEncoder();
bm = new Bitmap(smallBMD, PixelSnapping.ALWAYS, true);
PNGByteArray = x.encode(bm.bitmapData);
CurrentLogoBitmap = new Bitmap(bm.bitmapData);
});
ldr.loadBytes(logoFileRef.data);
logoFileRef.removeEventListener(Event.COMPLETE, onLoadComplete);
logoFileRef.addEventListener(Event.COMPLETE, logoUploadCompleteHandler);
}