ByteArray 到 BitmapData AS3 [英] ByteArray to BitmapData AS3
问题描述
我正在使用 com.adobe.images.PNGEncoder 将 bitmapData 编码为 byteArray.有没有办法不使用 Loader 将 byteArray 转换回 bitmapData?谢谢.
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.
我不想使用加载器的原因是它是异步的,我不想实现事件监听器.
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 中很常见.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!