Project Nayuki

Dumb PNG output (Java)

PNG file format overview

This Java library takes an array of pixel values and writes it as a PNG image file. My simple implementation is inefficient in many ways, but it behaves correctly and produces legal PNG files.

The PNG file format is widely supported for because it flexibly supports many color formats and has compression built in. (By contrast, the Windows BMP format has no compression, and the GIF format was patented in the past.) When I read the PNG file format specification, I realized that writing a basic compliant encoder wasn’t too difficult and wouldn’t take too much code. Thus this is the result of my effort.

Source code

The provided code includes two items:




If you want to write your own PNG encoder entirely from scratch (including the compression), these are the reference documents you need to read: