BITMAPINFO结构的bmiColors领域 [英] bmiColors field of BITMAPINFO structure

查看:317
本文介绍了BITMAPINFO结构的bmiColors领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BITMAPINFO 结构具有以下声明

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

为什么 RGBQUAD 阵列静态的?为什么不是指针?

Why is RGBQUAD array static? Why is it not a pointer?

推荐答案

这是一个标准的把戏声明的可变大小的结构。颜色表从未只有一个条目,它具有一个单色位图的至少2,通常为256要8bpp位图等由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计算。然后,一个简单的投地(BITMAPINFO *)使得它可以使用。

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.

这篇关于BITMAPINFO结构的bmiColors领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆