PNG libraries for C/C++
For C and C++ there are 4 good choices:
- libpng is the reference implementation and supports everything in the specification. Its classic API is verbose; the “simplified API” (
png_image) reads and writes whole images in a few lines. Needs zlib. - libspng has a smaller, safer API than libpng and decodes faster. Needs zlib or miniz.
- LodePNG is one
.cpp+.hfile with its own DEFLATE implementation: the easiest to add to a project. - stb_image is a single public-domain header that also reads JPEG, GIF, BMP, TGA and more. Good for games and tools; its PNG encoder (
stb_image_write) produces larger files.
Pick libpng or libspng for production code that handles untrusted files and needs metadata; LodePNG or stb_image when you want zero build setup.
- libpng libpng is the official PNG reference library for C and C++. How to install it, read and write PNG files with the simplified API, read text chunks.
- libspng libspng is a simple, fast C library for reading and writing PNG files, an alternative to libpng. How to decode a PNG to RGBA, read the header.
- LodePNG LodePNG is a single-file PNG decoder and encoder for C and C++ with no dependencies. How to add it to a project, decode and encode PNG files.
- stb_image stb_image and stb_image_write are single-header public domain C libraries for loading and saving PNG, JPEG, BMP, TGA and other images. How to load a PNG.