Graphics File Formats(Windows的.BMP .CUR .ICO文件的格式,有范例)
this topic describes the graphics-file formats used by the microsoft windows operating system. graphics files include bitmap files, icon-resource files, and cursor-resource files.
bitmap-file formats
windows bitmap files are stored in a device-independent bitmap (dib) format that allows windows to display the bitmap on any type of display device. the term "device independent" means that the bitmap specifies pixel color in a form independent of the method used by a display to represent color. the default filename extension of a windows dib file is .bmp.
bitmap-file structures
each bitmap file contains a bitmap-file header, a bitmap-information header, a color table, and an array of bytes that defines the bitmap bits. the file has the following form:
bitmapfileheader bmfh; bitmapinfoheader bmih; rgbquad acolors[]; byte abitmapbits[];
the bitmap-file header contains information about the type, size, and layout of a device-independent bitmap file. the header is defined as a bitmapfileheader structure.
the bitmap-information header, defined as a bitmapinfoheader structure, specifies the dimensions, compression type, and color format for the bitmap.
the color table, defined as an array of rgbquad structures, contains as many elements as there are colors in the bitmap. the color table is not present for bitmaps with 24 color bits because each pixel is represented by 24-bit red-green-blue (rgb) values in the actual bitmap data area. the colors in the table should appear in order of importance. this helps a display driver render a bitmap on a device that cannot display as many colors as there are in the bitmap. if the dib is in windows version 3.0 or later format, the driver can use the biclrimportant member of the bitmapinfoheader structure to determine which colors are important.
the bitmapinfo structure can be used to represent a combined bitmap-information header and color table. the bitmap bits, immediately following the color table, consist of an array of byte values representing consecutive rows, or "scan lines," of the bitmap. each scan line consists of consecutive bytes representing the pixels in the scan line, in left-to-right order. the number of bytes representing a scan line depends on the color format and the width, in pixels, of the bitmap. if necessary, a scan line must be zero-padded to end on a 32-bit boundary. however, segment boundaries can appear anywhere in the bitmap. the scan lines in the bitmap are stored from bottom up. this means that the first byte in the array represents the pixels in the lower-left corner of the bitmap and the last byte represents the pixels in the upper-right corner.
the bibitcount member of the bitmapinfoheader structure determines the number of bits that define each pixel and the maximum number of colors in the bitmap. these members can have any of the following values:
value meaning
1 bitmap is monochrome and the color table contains two entries. each bit in the bitmap array represents a pixel. if the bit is clear, the pixel is displayed with the color of the first entry in the color table. if the bit is |