我需要将图像中的像素从480 X 480减少到30 X 30.这需要对像素进行下采样,我没有看到任何方法来删除位图图像中的单个像素。
我需要这种下采样,因为我正在研究图像处理中的失真 - 在简短的一面。
任何帮助都将不胜感激。
答案 0 :(得分:1)
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.net.URLRequest;
public class DownSampling extends Sprite
{
private var _loader : Loader;
public function DownSampling()
{
_loader = new Loader;
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImgLoaded);
// Get the bitmap
_loader.load(new URLRequest("https://appharbor.com/assets/images/stackoverflow-logo.png"));
}
private function onImgLoaded(e : Event) : void
{
var currentBitmapdata : BitmapData = Bitmap(_loader.content).bitmapData;
var i : uint = 9;
var downFactor : Number = 0.2;
// this will reduce size by 20%
var downMat : Matrix = new Matrix;
downMat.scale(1 - downFactor, 1 - downFactor);
while(--i)
{
// Create new bitmapdata but smaller
var smallerImg : BitmapData = new BitmapData(currentBitmapdata.width * (1-downFactor), currentBitmapdata.height * (1-downFactor), true, 0);
// Copy and apply scale
smallerImg.draw(currentBitmapdata, downMat);
// Add to stage and set alpha to 50%
addChild(new Bitmap(smallerImg)).alpha = .5;
// Apply the same transform next loop
currentBitmapdata = smallerImg;
}
}
}
}
结果: