I am trying to display BMP 16 bit R5 G6 B5 image modifing BMPlib (http://www.osbald.co.uk) with no success
This is the code I have:
Image unpack16_565(byte[] rawData, int scanlineSize) {
int b = 0, k = 0, x = 0, y = 0;
byte red,green,blue;
int[] data = new int[bmp_infoheader.biWidth * bmp_infoheader.biHeight];
try {
for (y = 0; y < bmp_infoheader.biHeight; y++) {
b = (bmp_infoheader.biHeight - 1 - y) * bmp_infoheader.biWidth;
k = y * scanlineSize;
for (x = 0; x < bmp_infoheader.biWidth; x++) {
red = (byte) (rawData[k]>>3);
green = (byte) ((byte) (((rawData[k++]&0x7))<<3)|(rawData[k]>>5));
blue = (byte) ((byte) rawData[k++]&0x1f);
data[x + b] = 0xFF000000 | (((int)(red)) & 0xFF) | (((int)green) & 0xFF) << 8
| (((int)blue) & 0xFF) << 16;
}
}
} catch (Exception e) {
}
;
return Toolkit.getDefaultToolkit().createImage(
new MemoryImageSource(bmp_infoheader.biWidth, bmp_infoheader.biHeight, ColorModel.getRGBdefault(),
data, 0, bmp_infoheader.biWidth));
}
As far as I understand I have a byte[] of BMP. So I have to use bit operations to get from two bytes, 3 colors of the pixel
8 bit 8bit
[RRRRR GGG] [GGG BBBBB]
1 byte 1 byte
The result it the image with BROKEN colors.
If anybody could point what is wrong with the code, hints, links to examples, I would appreciate it…
Thanks!