public static byte[] Gray16BGR(byte[] bytes, int width, int height) {
byte[] bgr = new byte[width * height * 3];
int nCount =0;
for (int i=0;i< height;i++) {
for (int j = 0; j < width * 2; j= j+2) {
int nLow = Byte.toUnsignedInt(bytes[i * width * 2 + j]);
int nHigh = Byte.toUnsignedInt(bytes[i * width * 2 + j + 1]);
int nGray16 = nHigh;
nGray16 = nGray16 << 8;
nGray16 = nGray16 + nLow;
nGray16 = nGray16 >>2;
byte gray8 = (byte) (nGray16 &0xFF);
bgr[nCount] = gray8;
bgr[nCount+1] = gray8;
bgr[nCount+2] = gray8;
nCount+=3;
}
}
return bgr;
}