title: Creating 8 bit image from byte array
body: <p>The byte array is obtained this way -</p>
  
  <pre><code>BufferedImage image = new Robot().createScreenCapture(new Rectangle(screenDimension));
  byte[] array = ((DataBufferByte)getGraycaleImage(image).getRaster().getDataBuffer()).getData();
  //  Method getGraycaleImage returns a grayscaled BufferedImage, it works fine
  </code></pre>
  
  <p>now how do i reconstruct this grayscale image from the byte array?</p>
  
  <p>I don't know much about ARGB, RGB or grayscale images. I tried this -</p>
  
  <pre><code>private Image getGrayscaleImageFromArray(byte[] pixels, int width, int height)
  {
      int[] pixels2=getIntArrayFromByteArray(pixels);
      MemoryImageSource mis = new MemoryImageSource(width, height, pixels2, 0, width);
      Toolkit tk = Toolkit.getDefaultToolkit();
      return tk.createImage(mis);
  }
  
  private int[] getIntArrayFromByteArray(byte[] pixelsByte)
  {
      int[] pixelsInt=new int[pixelsByte.length];
      int i;
      for(i=0;i&lt;pixelsByte.length;i++)
          pixelsInt[i]=pixelsByte[i]&lt;&lt;24 | pixelsByte[i]&lt;&lt;16
  | pixelsByte[i]&lt;&lt;8 | pixelsByte[i];  // I think this line creates the problem
      return pixelsInt;
  }
  </code></pre>
  
  <p>When I draw this image it's not black and white, rather something like orange and gray.</p>