BITMMAPINFO 结构的 bmiColors 字段 [英] bmiColors field of BITMAPINFO structure
问题描述
BITMAPIINFO
结构具有以下声明
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO;
为什么 RGBQUAD
数组是静态的?为什么不是指针?
Why is the RGBQUAD
array static? Why is it not a pointer?
推荐答案
声明一个可变大小结构是一个标准的技巧.颜色表从来没有只有一个条目,对于单色位图它至少有 2 个条目,对于 8bpp 位图通常有 256 个条目,等等.由 bmiHeader.biClrUsed 成员指示.所以结构体的实际大小取决于位图格式.
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.
由于 C 语言不允许声明这样的数据结构,所以这是最接近的匹配.创建结构需要 malloc() 分配足够的字节来存储结构,根据 biClrUsed 计算.然后简单地转换为 (BITMAPIF0*) 使其可用.
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.
这篇关于BITMMAPINFO 结构的 bmiColors 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!