As you may read in my Twitter last week I was experimenting with asynchronous PNG image encoding and saving. It is very easy task until you need to save a really large/huge image file (for print purpose or whatever). As far as Flash don’t have ability to compress/deflate ByteArrays in append way or simply partly we surely will crash flash player while compressing image data for image larger then 10.000×10.000 px.
Joa provided a link to a flashzlib by Ed McManus and that way the “sign” to use Alchemy to process compression via ZLIB.
But what was my surprise when I found that we easily can compile original ZLIB sources in alchemy and use it in our Alchemy projects without any changes! And that was possible since December 2008! Can you believe it?
So I downloaded ZLIB sources and compile them in alchemy as the result I got static library I can append to any Alchemy project. All you need is to write wrapper C class to call functions in ZLIB and get the result back.
I also found brilliant optimized PNG class at wonderfl that used different filters for the image data. I’ve encapsulated that filters in my PNG encoder in both synchronous and asynchronous way. Alchemy is used only for the compress of image data all other operations done in Flash. It is also possible to compile PNGLIB for the Alchemy (as easy as ZLIB) but it will result in really huge *.swc file. So it is to you to decide.
See small demo app where you can encode large PNG files asynchronous with compress level and filter options.