So I've finally written code to detect all the correct RGB values for my bitmap, and store them.
BufferedImage image = new BufferedImage(adjWidth,
this.height,
BufferedImage.TYPE_3BYTE_BGR);
// start from bottom row
for(int i = this.height-1; i >= 0; i--) {
for(int j = 0; j < adjWidth-2; j += 3) {
int index = adjWidth*i + j;
int b = iData[index];
int g = iData[index+1];
int r = iData[index+2];
int rgb = ((r&0x0ff)<<16)|((g&0x0ff)<<8)|(b&0x0ff); // merge rgb values to single int
/*
System.out.printf("\nRow: %s\nColumn: %s\nRed: %s\n"
+ "Green: %s\nBlue: %s\n", i, j,
(rgb>>16)&0x0ff, (rgb>>8)&0x0ff, (rgb)&0x0ff);
System.out.println("Color value: " + rgb);
*/
// build image from bottom up
image.setRGB(j, this.height-i-1, rgb);
}
}
iData is a byte[] read from the file. I know my RGB values are correct after debugging their values, and also comparing them against a hex editor. AdjWidth is the width including padding.
However, my image is outputting with vertical black bands all along the image. I know the image is partially correct when I compare it to the source image, albeit it being a little distorted, but I think all of that sources from this problem. I suspect this is because j is being incremented by 3, so when I set the pixel value, it skips those pixels. How can I avoid this, and create the correct image?
Input bmp:
Output bmp:
edit I'm doing this as an exercise, by the way.