您确定需要 RGBA4444 格式吗?也许您需要一种旧格式,其中绿色通道获得 6 位,而红色和蓝色通道获得 5 位(总共 16 位)
如果是 5-6-5 格式 - 答案很简单。
做就是了
R = (R>>3); G = (G>>2); B = (B>>3);将 24 位减少到 16 位。现在只需使用 | 将它们组合起来操作。
这是 C 语言的示例代码
// Combine RGB into 16bits 565 representation. Assuming all inputs are in range of 0..255
static INT16 make565(int red, int green, int blue){
return (INT16)( ((red << 8) & 0xf800)|
((green << 2) & 0x03e0)|
((blue >> 3) & 0x001f));
}
上述方法使用与常规 ARGB 构造方法大致相同的结构,但将颜色压缩到 16 位而不是像以下示例中的 32 位:
// Combine RGB into 32bit ARGB representation. Assuming all inputs are in range of 0..255
static INT32 makeARGB(int red, int green, int blue){
return (INT32)((red)|(green << 8)|(blue<<16)|(0xFF000000)); // Alpha is always FF
}
如果您确实需要 RGBA4444,那么该方法将是上述两者的组合
// Combine RGBA into 32bit 4444 representation. Assuming all inputs are in range of 0..255
static INT16 make4444(int red, int green, int blue, int alpha){
return (INT32)((red>>4)|(green&0xF0)|((blue&0xF0)<<4)|((alpha&0xF0)<<8));
}