title: Java ImageIO, can't set pixel values?
body: <p>I have some really simple code that's just not working:</p>
  
  <pre><code>int[] manualPixels = new int[width * height * 3];
  for (int index = 0; index &lt; 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);
  </code></pre>
  
  <p>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 <code>if</code> statement in the <code>for</code> loop.  The problem is that instead of that, I invariably get blue and black stripes, no matter which pixels I set.  For instance:</p>
  
  <p><img src="https://i.stack.imgur.com/U0AC4.jpg" alt="enter image description here"></p>
  
  <p>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?</p>