调色板数据结构:
typedef struct tagPALETTEENTRY { BYTE peRed; BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY;
/palette storage
PALETTEENTRY palette[256];
然后用你希望的方式填满它们:
// build up the palette data array for (int color=1; color < 255; color++) { // fill with random RGB values palette[color].peRed = rand()%256; palette[color].peGreen = rand()%256; palette[color].peBlue = rand()%256;
// set flags field to PC_NOCOLLAPSE palette[color].peFlags = PC_NOCOLLAPSE; } // end for color
// now fill in entry 0 and 255 with black and white0号位置填黑色(亮度最暗) palette[0].peRed = 0; palette[0].peGreen = 0; palette[0].peBlue = 0; palette[0].peFlags = PC_NOCOLLAPSE;
//255最大填白色(亮度最亮)
palette[255].peRed = 255; palette[255].peGreen = 255; palette[255].peBlue = 255; palette[255].peFlags = PC_NOCOLLAPSE;
有一条规则:必须设置peFlags域为PC_NOCOLLASPE,因为你不希望Win32/DirectX优化你的调色板