1

看图片我正在尝试使用 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");
4

3 回答 3

1

您最初应该使用 .scaleX 和 .scaleY 增加剪辑的大小

mainclip.scaleX = mainclip.scaleY = 2;

通过更改宽度和高度,您只需增加剪辑容器的边界

我建议改用这个库,它更快。

于 2013-09-06T12:19:37.610 回答
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);
        }
于 2013-09-27T17:57:33.397 回答
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
于 2013-09-24T08:04:43.603 回答