Somebody told me that when a png image is stored in swf, it's separated to several layer, hence the alpha channel can be compressed better. Is it true? Or, once png image is imported into a swf, it's format is changed, e.g converted into bitmap data, and than compressed by swf's compress algorithm. That's, it is not in png format anymore.
I don't know how swf packing its resource, please tell me if you know.
-
\$\begingroup\$ As a note, the compression algorithm used by PNG is actually zlib. png might include some filtering that causes zlib to compress better than just zipping up the raw bitmap though. \$\endgroup\$– Jari KomppaJan 13, 2011 at 14:06
1 Answer
If you add a PNG image in the Flash IDE, you can choose JPEG compression for it. The interesting part about this is, that it will preserve alpha transparency.
So what internally happens is exactly as you describe. The alpha channel and the color information get separated and compressed individually. AFAIK the alpha will always be JPEG compressed whereas I'm not so sure about the image. I suspect that there is some analyzing going on and the algorithm then chooses either PNG or JPEG compression for the color data.
This only applies for the Flash IDE though (eg. Flash CS 5, Flash CS 4, etc.). In Flex, images aren't treated that way. However there's a tool that can do that with any existing SWF. It's called "reducer" and can be found here: http://blog.joa-ebert.com/2009/08/08/reducer/
Actually I encountered some weird behavior using Flex Builder a while back, where I compressed PNG game-assets using ImageOptim but the resulting SWF didn't decrease in filesize like I would have expected. This lead to this question on stackoverflow which isn't answered till today :)