ICO File FormatIcons are normally stored in ICO files. The ICO file format is documented in the Windows 3.1 SDK Programmer's Reference, Volume 4: Resources, Chapter 1: Graphics File Formats.The ICO file starts with an ICONDIR structure. The ICONDIR structure is defined as:typedef struct { WORD idReserved; // Reserved WORD idType; // resource type (1 for icons) WORD idCount; // how many images? ICONDIRENTRY idEntries[1]; // entries for each image (idCount of 'em) } ICONDIR, *LPICONDIR; The ICONDIRENTRY structure is defined as:typedef struct { BYTE bWidth; // Width of the image BYTE bHeight; // Height of the image (times 2) BYTE bColorCount; // Number of colors in image (0 if >=8bpp) BYTE bReserved; // Reserved WORD wPlanes; // Color Planes WORD wBitCount; // Bits per pixel DWORD dwBytesInRes; // how many bytes in this resource? DWORD dwImageOffset; // where in the file is this image } ICONDIRENTRY, *LPICONDIRENTRY; So, the file consists of the header followed by the bits for each image. The bits for each image can be located by seeking to dwImageOffset in the file. The format of the bits follows: The bits for each image are stored in something similar to CF_DIB format. First is a BITMAPINFO structure, followed by the DIB bits of the XOR mask, followed by the DIB bits of the AND mask. Note the following two caveats: 1) The bmiHeader.biHeight member of the BITMAPINFO structure indicates the height of the XOR mask plus the height of the AND mask. 2) The AND mask is monochrome, and has no BITMAPINFO.
MSDN中也有
the Windows 3.1 SDK Programmer's Reference, Volume 4: Resources,
Chapter 1: Graphics File Formats.The ICO file starts with an ICONDIR structure. The ICONDIR structure is
defined as:typedef struct
{
WORD idReserved; // Reserved
WORD idType; // resource type (1 for icons)
WORD idCount; // how many images?
ICONDIRENTRY idEntries[1]; // entries for each image (idCount of 'em)
} ICONDIR, *LPICONDIR;
The ICONDIRENTRY structure is defined as:typedef struct
{
BYTE bWidth; // Width of the image
BYTE bHeight; // Height of the image (times 2)
BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
BYTE bReserved; // Reserved
WORD wPlanes; // Color Planes
WORD wBitCount; // Bits per pixel
DWORD dwBytesInRes; // how many bytes in this resource?
DWORD dwImageOffset; // where in the file is this image
} ICONDIRENTRY, *LPICONDIRENTRY;
So, the file consists of the header followed by the bits for each image. The
bits for each image can be located by seeking to dwImageOffset in the file.
The format of the bits follows: The bits for each image are stored in something similar to CF_DIB format.
First is a BITMAPINFO structure, followed by the DIB bits of the XOR mask,
followed by the DIB bits of the AND mask. Note the following two caveats:
1) The bmiHeader.biHeight member of the BITMAPINFO structure indicates
the height of the XOR mask plus the height of the AND mask.
2) The AND mask is monochrome, and has no BITMAPINFO.