title: how do i create a 16-bit grayscale image with java
body: <p>Im trying to create a 16-bit PNG but cant get it keeps writing just black. Also how can i convert an 8-bit color defined as 255,255,255/r,g,b to a 16-bit color? </p>
  
  <pre><code>    BufferedImage bi = new BufferedImage(256, 256,
              BufferedImage.TYPE_USHORT_GRAY);
  
      // 65536
      for (int i = 0; i &lt; 256; i++)
          for (int j = 0; j &lt; 256; j++) {
              int mask = 0xf0
              int value = 255 &amp; mask; // zero other bits
              value &gt;&gt;= 16;
              bi.setRGB(i, j, value);
              // bi.setRGB(i, j, 65536);
          }
  
      File f = new File("gray.png");
  
      try {
          ImageIO.write(bi, "png", f);
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>