title: How to create 1-bits bitmaps using BufferedImage object?
body: <p>I'm trying to obtain a <strong>1-bits</strong> bitmap's RGB, put it in a multidimensional array to perform some tasks and recreate the bitmap again to its original form. 
  Although almost the same code worked just fine with 4-bits and 8-bit bitmaps my end result shows a black image for the 1-bits bitmaps, not really sure of what I've done wrong here!!
  Thanks in advance. </p>
  
  <pre><code>BufferedImage in = ImageIO.read(new File("D:\\SourceImage.bmp"));
  int w = in.getWidth(), h = in.getHeight();
  int[][] array = new int[w][h];
  for (int j = 0; j &lt; w; j++) {
      for (int k = 0; k &lt; h; k++) {
          array[j][k] = in.getRGB(j, k);
      }
  }
  
  // perform operations on array[ ][ ]
  
  byte[] v = new byte[2];
  for (int i = 0; i &lt; v.length; ++i) {
      v[i] = (byte) (i );
  }
  ColorModel cm = new IndexColorModel(1, v.length, v, v, v);
  WritableRaster wr = cm.createCompatibleWritableRaster(w, h);
  BufferedImage out = new BufferedImage(cm, wr, false, null);
  for (int y = 0; y &lt; h; y++) {
      for (int x = 0; x &lt; w; x++) {
          int Pixel = array[x][y] &lt;&lt; 16 | array[x][y] &lt;&lt; 8 | array[x][y];
          out.setRGB(x, y, array[x][y]);
      }
  }
  Graphics2D g = out.createGraphics();
  g.drawImage(out, 0, 0, null);
  g.dispose();
  ImageIO.write(out, "bmp", new File("D:\\ResultImage.bmp"));
  </code></pre>