views:

2205

answers:

1

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?

+2  A: 

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 ...

back2dos
Thanks again. ::sigh:: So I guess there's no straight-forward way for me to synchronously load BitmapData then?
grey
i'm afraid no ... if you find one, please tell me ... :)you can always hope, hxformat (http://code.google.com/p/hxformat/) will one day finally include a PNG decoder and then compile an swc that you can use in your project, but until then, i don't even know of a lib doing the job for you ... or maybe, one day there will be a synchronous version of `Loader::loadBytes` (which would really be VERY cool in some scenarios) ... good luck anyway ... ;)
back2dos
I spent a day on a PNG decoder. Never done that before. I got most of it done ( messily ), but undoing the filtering is a little tricky. I have more important things to make progress on at the moment, but if I get time to finish it later, I'll let you know.
grey
I keep looking at the PNGDecoder... and while it sorta works - it gets all the chunks and what not... the thought of implementing all of the different types of interlacing is a bit above me at the moment. I'm using loadBytes from the synchronously loaded PNG data.PNG > File > FileStream > ByteArray > Loader.loadBytes > BitmapData
grey