Smuggle: A png utility

2009 April 04

Ric on the flashkit forums was having a hell of a time getting the scrabble dictionary into flash without loading it dynamically at runtime. For some reason, the flash compiler was just plain choking on the size of the actionscript. So, I created this utility to enable you to encode one file as a png, and to decode such a png back into a file.

I apologize for the complete lack of visual polish, I have an immense headache.

In your own projects, you'll need to use the PNGSmuggler class to decode the png back into a bytearray. That's pretty easily done, like this:

     var bytes:ByteArray = PNGSmuggler.decodePNG(bitmapdata);
   

From that bytearray, it's up to you how to interpret it.

Source of utility, and the PNGSmuggler class are here

There is a size limit on the files, about 2^24 bytes. That's about 16MB, so you should have plenty of room for anything you'd want to embed in the first place.

The encoding scheme does waste a lot of space, unfortunately. Due to the fact that flash stores bitmapdata pixels internally in a premultiplied manner, the alpha channel must always be FF. And for ease of implementation, I made the green channel always FF too. If someone wants to go in and use that green channel for something useful, be my guest.

Update 4/12/09: green channel now used, resulting pngs much smaller.

privacy policy
Sponsored links