Preface
We all know that during the development of the mobile phone application program for j2's, we can use images in PNG format (even on some mobile phones, we can only use images in PNG format), although using images can add many highlights to our application, however, only images in PNG format are supported, but the possibility of further improvement is limited (in fact, it should be said that the processing capability on the mobile phone platform is Limited ). The drawPixels/getPixels methods are provided in MIDP2 or APIs provided by some vendors (such as NOKIA). These methods are further improved Development Users can process images flexibly. However, we need to use. 0 implementation of this type of method is still whimsical, so in order to achieve more advanced applications, we must fully tap the potential of PNG.
PNG file structure
For a PNG file, the file header is always described by fixed Bytes:
Decimal number |
137 80 78 71 13 10 26 10 |
Hexadecimal number |
89 50 4E 47 0D 0A 1A 0A |
The first byte 0x89 is out of the ASCII character range to prevent some software from processing PNG files as text files. The remaining parts of the file are composed of more than three PNG data blocks (Chunk) in a specific order. Therefore Standard The PNG file structure of should be as follows:
PNG file flag |
PNG data block |
...... |
PNG data block |
PNG data block (Chunk)
PNG defines two types of data blocks. One is critical chunk, which is a standard data block, and the other is ancillary chunks ), this is an optional data block. Key data blocks define four standard data blocks. Each PNG file must contain them. PNG read/write software must also support these data blocks. Although the PNG file specification does not require the PNG encoding/Decoding of optional data blocks, the specification advocates the support of optional data blocks.
The following table lists the types of data blocks in PNG. The key data blocks are distinguished by the dark background.
Data blocks in PNG file format |
Data Block symbol |
Data Block name |
Multiple Data blocks |
Optional |
Location restrictions |
IHDR |
File header data block |
No |
No |
First |
CHRM |
Base color and white point data block |
No |
Yes |
Before PLTE and IDAT |
GAMA |
Image gamma data block |
No |
Yes |
Before PLTE and IDAT |
SBIT |
Sample valid BIT data block |
No |
Yes |
Before PLTE and IDAT |
PLTE |
Color Palette data block |
No |
Yes |
Before IDAT |
BKGD |
Background color data block |
No |
Yes |
Before IDAT after PLTE |
HIST |
Image histogram data block |
No |
Yes |
Before IDAT after PLTE |
TRNS |
Transparent data block |
No |
Yes |
Before IDAT after PLTE |
OFFs |
(Private Public Data blocks) |
No |
Yes |
Before IDAT |
PHYs |
Physical pixel size data block |
No |
Yes |
Before IDAT |
SCAL |
(Private Public Data blocks) |
No |
Yes |
Before IDAT |
IDAT |
Image Data Block |
Yes |
No |
Continuous with other IDAT |
TIME |
Last modification time data block of the image |
No |
Yes |
Unlimited |
TEXt |
Text Information Data Block |
Yes |
Yes |
Unlimited |
ZTXt |
Compressing text data blocks |
Yes |
Yes |
Unlimited |
FRAc |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
GIFg |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
GIFt |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
GIFx |
(Private Public Data blocks) |
Yes |
Yes |
Unlimited |
IEND |
Image end data |
No |
No |
Last data block |
For the sake of simplicity, we assume that in the PNG file we use, the four data blocks are stored in the above Order, and only appear once.
Data Block Structure
In a PNG file, each data block consists of four parts:
Name |
Bytes |
Description |
Length) |
4 bytes |
Specifies the length of the data field in a data block. The length cannot exceed (231-1) bytes. |
Chunk Type Code (data block Type Code) |
4 bytes |
The data block type code consists of ASCII letters (A-Z and a-z) |
Chunk Data (Data block Data) |
|