title: Create a buffered image from rgb pixel values
body: <p>I have an integer array of RGB pixels that looks something like:</p>
  
  <pre><code>pixels[0] = &lt;rgb-value of pixel(0,0)&gt;
  pixels[1] = &lt;rgb-value of pixel(1,0)&gt;
  pixels[2] = &lt;rgb-value of pixel(2,0)&gt;
  pixels[3] = &lt;rgb-value of pixel(0,1)&gt;
  ...etc...
  </code></pre>
  
  <p>And I'm trying to create a BufferedImage from it. I tried the following:</p>
  
  <pre><code>BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  img.getRaster().setPixels(0, 0, width, height, pixels);
  </code></pre>
  
  <p>But the resulting image has problems with the color bands. The image is unclear and there are diagonal and horizontal lines through it.</p>
  
  <p>What is the proper way to initialize the image with the rgb values?</p>
  
  <p>EDIT:
  Here is what my image looks like<img src="https://i.stack.imgur.com/65JQb.jpg" alt="alt text"></p>
  
  <p>thanks,
  Jeff</p>