converting [RRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA] to [RRRRRGGGGGBBBBBA]
I am writing an ImageEncoder that writes a TGA image. I have been able to
successfully write the TGA file, but instead of ending up with
[RRRRRGGGGGBBBBBA] I get [RGBBBBBA] here is the relevant code:
int lastRow = minY + height;
for (int row = minY; row < lastRow; row += 8) {
int rows = Math.min(8, lastRow - row);
int size = rows * width * numBands;
// Grab the pixels
Raster src = im.getData(new Rectangle(minX, row, width, rows));
src.getPixels(minX, row, width, rows, pixels);
for (int i = 0; i < size; i++) {
//output.write(pixels[i] & 0xFF);
short o = (short) pixels[i];
byte[] reo = new byte[2];
reo[0] = (byte) (o & 0xff);
reo[1] = (byte) ((o >> 8) & 0xff);
output.write(reo);
}
}
No comments:
Post a Comment