ByteArray for BitmapData AS3

I am using com.adobe.images.PNGEncoder to encode bitmapData in byteArray. Is there a way to convert byteArray back to bitmapData NOT using Loader? Thank you

EDIT: the reason I don't want to use Loader is asynchronous, and I don't want to implement eventlisteners.

+6
source share
2 answers

Next, the bootloader class is used, but it is synchronous.

var loader:Loader = new Loader(); loader.loadBytes(byteArray); bmpData.draw(loader); 

Change Never forget that loadBytes is also asynchronous, the documentation says you need to wait for the init event. What is the reason for the unwillingness of event listeners? This is a fairly 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); 
+10
source

Take a look at the setpixels () bitmapdata method. It requires the rectangle to size and bytearray as content. This method is synchronous

+2
source

Source: https://habr.com/ru/post/920797/


All Articles