I have some really simple code that's just not working:
int[] manualPixels = new int[width * height * 3];
for (int index = 0; index < manualPixels.length; index++) {
if (index % 3 == 2) {
manualPixels[index] = 255;
}
}
BufferedImage pixelImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
pixelImage.setRGB(0, 0, width, height, manualPixels, 0, width);
ImageIO.write(pixelImage, "jpeg", tempFile);
This should, as far as I can determine, output a red, green, or blue image, depending upon whether 0, 1, or 2 is used in the if
statement in the for
loop. The problem is that instead of that, I invariably get blue and black stripes, no matter which pixels I set. For instance:
I'm sure there must be some basic thing that I'm doing wrong here, I'm just not seeing what it is. Any ideas?