bmiColors field of BITMAPINFO structure

后端 未结 3 1544
孤独总比滥情好
孤独总比滥情好 2020-12-21 19:03

The BITMAPINFO structure has the following declaration

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


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 19:37

    It is a standard trick to declare a variable sized struct. The color table never has just one entry, it has at least 2 for a monochrome bitmap, typically 256 for a 8bpp bitmap, etc. Indicated by the bmiHeader.biClrUsed member. So the actual size of the struct depends on the bitmap format.

    Since the C language doesn't permit declaring such a data structure, this is the closest match. Creating the structure requires malloc() to allocate sufficient bytes to store the structure, calculated from biClrUsed. Then a simple cast to (BITMAPINFO*) makes it usable.

提交回复
热议问题