我正在尝试使用JPGEncoder类JPG Encoder创建一个图像mainclip的原始大小是540 X 180我尝试以相同的比例增加图像的大小但是获得半填充图像的空白部分。
mainclip.width=1080;
mainclip.height=360;
var myBitmapData:BitmapData = new BitmapData(mainclip.width,mainclip.height);
myBitmapData.draw(mainclip);
var jpgEncoder:JPGEncoder = new JPGEncoder(100);
var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);
fileRef.save(imgByteData, "test.jpg");
答案 0 :(得分:1)
您最初应使用.scaleX和.scaleY
增加剪辑的大小mainclip.scaleX = mainclip.scaleY = 2;
通过更改宽度和高度,您只需增加剪辑容器边界
我建议使用this lib代替它,它会更快。
答案 1 :(得分:0)
这里是代码
var scale:Number = 5;
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);e
答案 2 :(得分:0)
使用此
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);
}