入門到AS3位圖的東西...AS3轉換ByteArray的位圖
當我嘗試做下面的代碼失敗
bmd.setPixels(bmd.rect,decodeValue);
和錯誤消息是: 錯誤:錯誤#2030:遇到文件結尾。
這種情況是我通過轉換byteArray將圖像作爲二進制存儲到數據庫中,現在我想檢索它並將其轉換回圖像。
只是要清除這個ByteArray需要放置到位圖,然後你可以添加到電影剪輯吧?
import flash.display.Loader;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.display.BitmapData;
import com.dynamicflash.util.Base64;
var loader:Loader;
var req:URLRequest;
var orig_mc:MovieClip;
var copy_mc:MovieClip;
function loaderCompleteHandler(evt:Event) {
//swap data
var ldr:Loader = evt.currentTarget.loader as Loader;
var origImg:Bitmap = (ldr.content as Bitmap);
var origBmd:BitmapData = origImg.bitmapData;
trace(origImg.bitmapData);
trace(origImg.width);
trace(origImg.height);
//Convert image byteData into Base64 String
var byteArray:ByteArray = new ByteArray();
byteArray.writeObject(origBmd);
var encoded:String = Base64.encodeByteArray(byteArray);
trace("\nENCODED:\n" + encoded);
var decoded:ByteArray = Base64.decodeToByteArray(encoded);
trace("\nDECODED:\n" + decoded.toString());
// convert base64 string back into movieclip
var newBmd:BitmapData = new BitmapData(origImg.width,origImg.height,"true",0xFFFFFFFF);
newBmd.setPixels(origBmd.rect, decoded);**// THIS THROWS AN " Error #2030: End of file was encountered."**
var image:Bitmap = new Bitmap(newBmd, "auto", true);
copy_mc.addChild(image);
copy_mc.x = origImg.width;
}
loader = new Loader();
req = new URLRequest("C:\\Data\\cutcord.jpg");
loader.load(req);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
// movieclip to display original image
orig_mc = new MovieClip();
orig_mc.addChild(loader);
addChild(orig_mc);
// movieclip to display image copy
copy_mc = new MovieClip();
addChild(copy_mc);
Anyone can help would be very appreciated :)
我正在做你準備好的東西,但我一直在拋出這個錯誤:Error:Error#2030:End of file was encountered。是否因爲我的byteArray太大? – Bruce 2012-01-10 04:47:39
90068是長度,當我做一個跟蹤btw – Bruce 2012-01-10 05:23:49
有沒有一種方法來計算/從這樣的bytearray獲得原始尺寸? – SzRaPnEL 2013-07-15 23:06:45