我正在开发一个Java应用程序,它必须对BGR555颜色格式进行解码和编码。
解码过程的工作方式如下:
short rgb;
int r,g,b;
r=(num & 0x001F) * 0x08;
g=((num & 0x03E0) >> 5) * 0x08;
b=((num & 0x7C00) >> 10) * 0x08;问题是当我想从r,g,b值开始编码时。我不是按位操作的专家,我在网上搜索教程,但我不明白:
我的问题是怎么做?什么是相反的&以及如何连接值?
发布于 2014-08-19 11:55:45
我找到解决办法了!下面是片段:
public static byte[] fromBGR555(Color[] p) {
ByteBuffer b = ByteBuffer.allocate(p.length * 2).order(
ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < p.length; i++) {
int num = 0;
num += (p[i].getRed() / 0x08);
num += ((p[i].getGreen() / 0x08) << 5);
num += ((p[i].getBlue() / 0x08) << 10);
b.putShort((short) num);
}
return b.array();
}https://stackoverflow.com/questions/25363951
复制相似问题