BITMAPINFO结构体的一个疑问 RRS feed

  • 问题

  • 今天编一个显示位图的程序,使用了StretchDIBits函数,它的倒数第二个参数是BITMAPINFO结构体指针。BITMAPINFO结构体是这样定义的:

     typedef struct tagBITMAPINFO {
      BITMAPINFOHEADER  bmiHeader;
      RGBQUAD       bmiColors[1];


    The BITMAPINFO structure defines the dimensions and color information for a DIB. 

    typedef struct tagBITMAPINFO { 
      BITMAPINFOHEADER bmiHeader; 
      RGBQUAD bmiColors[1]; 
    Specifies a BITMAPINFOHEADER structure that contains information about the dimensions of color format. 

    The bmiColors member contains one of the following: 
    An array of RGBQUAD. The elements of the array that make up the color table. 
    An array of 16-bit unsigned integers that specifies indexes into the currently realized logical palette. This use of bmiColors is allowed for functions that use DIBs. When bmiColors elements contain indexes to a realized logical palette, they must also call the following bitmap functions: 



    The iUsage parameter of CreateDIBSection must be set to DIB_PAL_COLORS. 

    The number of entries in the array depends on the values of the biBitCount and biClrUsed members of the BITMAPINFOHEADER structure. 

    The colors in the bmiColors table appear in order of importance. For more information, see the Remarks section.

    A DIB consists of two distinct parts: a BITMAPINFO structure describing the dimensions and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in the array are packed together, but each scan line must be padded with zeroes to end on a LONG data-type boundary. If the height of the bitmap is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is a top-down DIB and its origin is the upper left corner. 

    A bitmap is packed when the bitmap array immediately follows the BITMAPINFO header. Packed bitmaps are referenced by a single pointer. For packed bitmaps, the biClrUsed member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap array starts on a DWORD boundary. 

    Note The bmiColors member should not contain palette indexes if the bitmap is to be stored in a file or transferred to another application. 

    Unless the application has exclusive use and control of the bitmap, the bitmap color table should contain explicit RGB values. 






    2011年8月21日 6:36



  • 调色板,一般256色一下的都有调色板
    • 已标记为答案 Rob Pan 2011年8月26日 8:43
    2011年8月21日 10:51
  • 柔性数组(Flexible Array)

    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
    2011年8月22日 0:56