Reducing J2ME Size with Advanced PNG Compression

One way to reduce the size of a J2ME application is through better compression of the PNG images you are using.

I currently use the excellent Paint.Net to create my images. Unfortunately, it doesn’t compress PNG output very effectively. It is particularly poor with monochrome images. Ideally, these would be saved in 2-bit color mode, but the best Paint.Net can do is 8-bit color. Surprisingly, this limitation is not unique to Paint.Net: numerous other tools have the same limitation. For example, I have created a monochrome image (containing a bitmapped font) and this was saved by Paint.Net using 8-bit color. It weighed in at 2352 bytes.

One of Paint.Net’s best features is its support for a wide range of plugins. One of these is able to host a PNG compressor called OptiPng. This is able to save 2-bit color and reduce the file down to just 928 bytes. A huge improvement.
Better still, a stand-alone little utility called PngGantlet uses the incredible PNGOOUT compressor to achieve even better results. It was able to shrink this image down to a mere 806 bytes: that’s just 34% of the size of the original image, with no loss of quality.

This is all the more impressive when you consider that the same image as a BMP file comes in at a massive 14,902 bytes (806 = 5.4% of 14902).
Here’s a summary of my results:

File Size (bytes) ~%
BMP 14,902 633%
Original PNG Image 2352 100%
OptiPNG 928 39%
PngGantlet 806 34%

One caveat – these figures don’t take into account any additional compression undertaken when converting the final application into a .jar file. I assume this compression will be less effective on the final 806-byte file than the original 2353-byte file.

Nevertheless, I don’t doubt that applying the compressor to all my images will result in a significantly smaller application.

Mini Book Review: Graphics Programming in Windows (Charles Petzold)

My personal library is overcrowded, so over the years I have found it necessary to dispose of many books on outmoded technology. This book by Charles Petzold is different. Indeed, its unparalleled coverage of graphics programming techniques make it worth every inch of the space it takes up on my shelf.

Although this it was written some time in the 1990s, it has become a timeless classic. Its contents apply to modern versions of Windows, as well as any other platform you care to mention. Of course, it lacks detail about the innovations that have occurred since it was written, but the programming techniques that it espouses are as useful as ever they were. Indeed, it is hard to find fault with a single example given in this volume.

Some people may find the book a little brief, in places. It lacks the depth of found in Petzold’s other books. Nevertheless, this book is without comparison in its subject area. If anyone is looking for a book on Windows Graphics, you’d be hard pressed to find one that is as informative as this one.

Sadly, Amazon lists this book as out of print. But, if you can obtain a copy of this book, I urge you to buy it.