Reputation: 1150
I want to use FileSteam.open() to synchronously read image files from disk. I can then get them into a ByteArray with readBytes(), but I can't find how to get that into BitmapData. I know Image can read it as is, but I need BitmapData.
Any suggestions?
Upvotes: 0
Views: 8600
Reputation: 19026
This library on github has a PNGDecoder that works synchronously. Give it a try:
https://github.com/terrynoya/ASImageLib
From the usage wiki:
var bytes:ByteArray = [PNG bytes];
var bmpData:BitmapData = new PNGDecoder().decode(bytes);
this.addChild(new Bitmap(bmpData));
But I'd imagine using the built-in class would be faster, and while it depends on your use-case, typically when dealing with UI like images, asynchronous is preferred to avoid blocking the UI thread (causing the app to stutter). But there could be some use cases.
Upvotes: 0
Reputation: 1607
It have sense, because FileStream works to manage pure data, and BitmapData works for compile or decompile data.
The way Im about to use, is to read the file in the origin and write a temporary file in the application directory, which may be reached by Loader class without troubles.
Wish me luck!
Upvotes: -1
Reputation: 15623
in the package flash.display
, use Loader::loadBytes
... that'll give you a Bitmap
, and the BitmapData
can then be simply accessed through Bitmap::bitmapData
... this makes the whole operation asynchronous, of course ... the only thing you could do, is write a decoder yourself ...
now there is a PNG encoder in AS3, in the as3corelib and i guess there are even others, but probably most people considered it pointless to write a decoder, since flash does this in its own, and also encoding is easier than decoding, because decoding means, you have to implement the whole format ... still, you can give it a shot of course ...
well, hope that helps ...
greetz
back2dos
Upvotes: 5