来源:http://www.riarock.com/
Tinic Uro 提供的 PNG Encoder 和 JPEG Encoder, 讚喔 !
原來的檔案是 for Flex 2.0, 所以記得把 Void 改成 void,
flash.util.* 也要改成 flash.utils.*
PNGEnc 裡的 shr(p,24) 要改成 p>>>24
例子: --------------
import flash.display.*;
import flash.net.URLRequest;
var loader:Loader = new Loader();
var url:String = "dog_lion.jpg";
var urlReq:URLRequest = new URLRequest(url);
loader.load(urlReq);
addChild(loader);
var info = loader.contentLoaderInfo;
info.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(e:Event){
var pic = e.target.content;
var bpd:BitmapData = new BitmapData(pic.width, pic.height);
bpd.draw(pic);
var jpegEnc:JPEGEncoder = new JPEGEncoder(80);
var dat:ByteArray = jpegEnc.encode(bpd);
trace(dat.length);
var loader2:Loader = new Loader();
this.addChild(loader2);
loader2.loadBytes(dat);
loader2.x = 100;
loader2.y = 100;
}
--------------
類別檔: PNGEnc.as, JPEGEncoder.as