PNG is extensible file format for the lossless, portable, well-compressed storage of raster images. PNG provides a patent-free replacement for GIF and can also replace many common uses of TIFF. Indexed-color, grayscale, and truecolor images are supported, plus an optional alpha channel. Sample depths range from 1 to 16 bits.
Images can also be filtered using different lossless filter for each scanline so that subsequent compression can produce even smaller images. PNG also supports interlaced images to allow progressive display. Imaging can load all possible PNG data formats but cannot save 1, 2, and 4 bit or interlaced images. It supports all filters when loading or saving images. Imaging uses ZLib library written by Jean-loup Gailly and Mark Adler to compress and decompress PNG image data. It was translated to Pascal by Jacques Nomssi Nzali.
As of version 0.26.4, Imaging also supports APNG format. APNG is unofficial extension of PNG image file format created by two guys from Mozilla Corporation. The point of APNG is to allow storing simple animations in PNG files (hence the "A" for "Animated"). There is already PNG-like chunk based format for animations called MNG (already supported by Imaging - at least the basic features). However, MNG is quite complex format and its support among browsers and image viewers/editors is lacking. Code library supporting all MNG features is huge. APNG on the other hand is just an extension of PNG and its implementation is not so complex. Imaging can load APNG files, animate them (optional - put frames at desired positions, blend frames, apply disposal methods), and also save multiple images as single APNG file.
Portable Network Graphics File Format SupportFormat | TImageFormat equivalent | Loading | Saving |
---|---|---|---|
1 bit indexed |
ifIndex8
| Yes | No |
2 bit indexed |
ifIndex8
| Yes | No |
4 bit indexed |
ifIndex8
| Yes | No |
8 bit indexed |
ifIndex8
| Yes | Yes |
24 bit RGB |
ifR8G8B8
| Yes | Yes |
48 bit RGB |
ifR16G16B16
| Yes | Yes |
32 bit ARGB |
ifA8R8G8B8
| Yes | Yes |
64 bit ARGB |
ifA16R16G16B16
| Yes | Yes |
1 bit grayscale |
ifGray8
| Yes | No |
2 bit grayscale |
ifGray8
| Yes | No |
4 bit grayscale |
ifGray8
| Yes | No |
8 bit grayscale |
ifGray8
| Yes | Yes |
16 bit grayscale |
ifGray16
| Yes | Yes |
16 bit grayscale + alpha |
ifA8Gray8
| Yes | Yes |
32 bit grayscale + alpha |
ifA16Gray16
| Yes | Yes |
When working with PNG files you can find useful some options which can be set by SetOption function and their current values can be get by GetOption function. Or you can set them by modifying properties of TPNGFileFormat class.
Options Related to PNG FilesOptionId | Allowed Values | Usage |
---|---|---|
ImagingPNGPreFilter | 0, 1, 2, 3, 4, 5, 6 | Sets precompression filter used when saving PNG images. Allowed values
are:
|
ImagingPNGCompressLevel | 0 (no compression) to 9 (best compression) | Sets ZLib compression level used when saving PNG images. Default value is 5. |
ImagingPNGLoadAnimated | 0 (false) or 1 (true) | Boolean option that specifies whether PNG images with more frames (APNG format) are animated by Imaging (according to frame disposal/blend methods) or just raw frames are loaded and sent to user (if you want to animate APNG yourself). Default value is 1. |