快速双立方或双线性图像在Flash中调整大小 - Flex - actionscript 3

时间:2011-01-13 11:33:24

标签: flex flash algorithm actionscript image-processing

我需要调整动作中的图像大小,保持质量,即双三次或双线性调整大小。目前,我的算法只循环遍历每个像素并计算新像素。例如:

            /* Loop through the pixels of the output image, fetching the equivalent pixel from the input*/
            for (var x:int = 0; x < width; x++) {
                for (var y:int = 0; y < height; y++) {
                                                bitmapDataTemp2.setPixel(x, y, newBitmapData2.getPixelBilinear(x * xFactor, y * yFactor));
                                                //bitmapDataTemp2.setPixel(x, y, newBitmapData2.getPixelBicubic(x * xFactor, y * yFactor));
                }
            }

这真的很慢而且很可耻闪存播放器中没有多线程,所以我想知道我可以用什么技巧加快速度?

非常感谢。

1 个答案:

答案 0 :(得分:1)

您应该使用BitmapData.setVector()而不是setPixel。看看这个例子:

var canvas:BitmapData=new BitmapData(255,255,false,0x000000);
addChild(new Bitmap(canvas, "auto", true));
 
var size:int = canvas.width * canvas.height;
var cols:int = canvas.width;
 
var pixels:Vector.<uint> = new Vector.<uint>(size);
 
canvas.lock();
for (var i:int  = 0; i<size; i++) {
    var ox:uint= i % cols;
    var oy:uint= i / cols;
    // just an example of what you can do:
    // pixels[i] = oy <<16 | ox;
    pixels[i] = newBitmapData2.getPixelBilinear(ox * xFactor, oy * yFactor);
}
   
canvas.setVector(canvas.rect, pixels);
canvas.unlock();

您应该考虑内联newBitmapData2.getPixelBilinear函数。这样做也会大大加快速度。