There are now a number of icons in the ICO format, the ICO icon file can store a single pattern, and can store multiple sizes, multi-color panels. Let's take a look at the following ICO icon file format composition.
Icon file format
The icon file (*.ico) consists of three parts of the icon file header, picture entry data, and picture data, which are detailed in the following three sections:
1. Icon file header
The icon file header consists of three parts, 6 bytes, respectively
Data type
Bytes
Meaning
Description
Word
2
Reserved Fields (wreserved)
Must be 0
Word
2
File Type (wtype)
Must be 1
Word
2
Number of pictures (Wcount)
Indicates how many pictures the icon file contains
2. Picture entrance
Next is the Wcount "picture entry" data. Each "Picture entry" data structure is as follows:
Data type
Bytes
Meaning
Description
BYTE
1
Image width (bwidth)
Unit: Pixel. 256PX Picture This value is 0
BYTE
1
Image Height (bheight)
Ditto
BYTE
1
Number of colors (bclrcount)
Not important
BYTE
1
Reserved Fields (breserved)
Must be 0
Word
2
Number of planes (Wplanes)
Generally for 1
Word
2
Bit number (Wbitcount)
Color depth, 4-bit, 8-bit, 24-bit, and 32-bit
DWORD
4
Data size (dwimagesize)
Number of bytes corresponding to picture data
DWORD
4
Data location (dwoffset)
The position of the corresponding picture data in the file
3. Picture data
For images with 256x256 pixels, the format stored in the file is PNG, as long as the entire PNG file is written in the data area, the corresponding data size (dwimagesize) for the previous picture entry is also the size of the PNG file. However, the XP operating system does not recognize the image.
For other pictures, the area holds a data bitmap of the target color depth (wbitcount) followed by a corresponding mask bitmap. The system Srcand the mask bitmap to the target device "and", and then copies the data bitmap to the target device "XOR" (Srcinvert) when drawing the icon.
The color depth of the data bitmap can be 4-bit 16-color, 8-bit 256-color, 24-bit true-color, or 32-bit with alpha channels. It should be noted that even a 32-bit bitmap with an alpha channel requires a mask bitmap.
The Mask bitmap is a 2-value bitmap with a 1-bit color depth, where the image is filled with 0, and the transparent position is filled with 1.
The structure of the data bitmap is basically similar to the normal bitmap structure, but the 14-bit bitmap file header is missing. Contains bitmap information header, color table (only 4-bit and 8-bit bitmap will have, 4-bit bitmap color table length is 16x4=64 byte, 8-bit bitmap color table length is 256x4=1024 byte) and data area.
The bitmap information header structure is as follows:
Data type
Bytes
Meaning
Description
DWORD
4
Structure Size (bisize)
Fixed to 40
LONG
4
Image width (biwidth)
Unit: Pixel
LONG
4
Image Height (biheight)
Unit: Pixel. Because there's a mask, so you want x 2.
Word
2
Number of planes (biplanes)
Generally for 1
Word
2
Bit number (biBitCount)
Color depth, 4-bit, 8-bit, 24-bit, and 32-bit
DWORD
4
Compression (Bicompression)
Generally for 0
DWORD
4
Data size (biSizeImage)
LONG
4
Resolution (Bixpelspermeter)
LONG
4
Resolution (Biypelspermeter)
DWORD
4
Use Color (biclrused)
DWORD
4
Important Color (biclrimportant)
To obtain a data bitmap, you can use the following methods:
First use the CImage class to create a bitmap of the target size and color depth. Note: 4-bit and 8-bit bitmaps need to set the color table, otherwise the data cannot be copied from the source picture, and the color table can be fixed with data. The 32-bit bitmap requires the alpha channel to be turned on, or the alpha channel data cannot be copied.
Then use CIMAGE::GETDC, Cimage::releasedc, CImage:: Getpixeladdress and CImage::D Raw and other functions to copy image data from the source diagram to the bitmap.
The bitmap is then saved to a temporary bitmap file. Read from the file.