An RGB color system can represent 256 different colors by combining different shades of red, green and blue. Each shade can be represented as a number. Define a C type to represent the RGB state.
根据我的理解,这将是一个合适的 C 类型,但不确定我是否正确:
struct{
int R[256];
int G[256];
int B[256];
} color;
这是正确的还是有更合适/更有效的方法?
最佳答案
您所需要的只是一个可以容纳三个 值的结构,每个值都在0..255
范围内。您建议的结构包含 3*256 * sizeof(int) = 768 * sizeof(int),太多了。改用这个:
struct color {
unsigned char R;
unsigned char G;
unsigned char B;
};
注意结构标识符 color
的正确位置。
您可以像这样在您的程序中进一步使用此结构:
struct color bright_orange;
bright_orange.R = 255;
bright_orange.G = 128;
bright_orange.B = 0;
关于c - RGB 颜色系统作为数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22849623/