问题描述
我用com.adobe.images.PNGEn codeR为en code位图数据为ByteArray。有没有办法不使用装载机的ByteArray转换回位图数据?谢谢。
I'm using com.adobe.images.PNGEncoder to encode bitmapData to a byteArray. Is there a way to convert the byteArray back to bitmapData NOT using a Loader? thanks.
编辑:我不想使用Loader的原因是它是异步的,我不希望实施EventListeners的
the reason i don't want to use a Loader is it being Asynchronous, and I don't want to implement eventlisteners.
推荐答案
在使用装载机类,但同步以下。
The following is using the loader class but is synchronous.
var loader:Loader = new Loader();
loader.loadBytes(byteArray);
bmpData.draw(loader);
修改:没关系的loadBytes是异步过,文件说,你需要等待init事件。什么是不希望事件侦听器的原因是什么?他们是在AS3一个pretty的通行做法。
Edit: Nevermind the loadBytes is asynchronous too, the documentation says you need to wait for the init event. What is the reason for not wanting event listeners? They are a pretty common practice in AS3.
所以,你需要的东西是这样的:
So you need something like this :
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void {
bmpData.draw(loader);
});
loader.loadBytes(byteArray);
这篇关于ByteArray的的BitmapData AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!