title: PNG read and write with Java increases file size
body: <p>Got a problem when reading and writing a png file. I read it with ImageIO to a byte array and then write this byte array again using ImageIO. But the file size increases significantly. How can this happen?</p>
  
  <pre><code>public BufferedImage toBufferedImage(InputStream inputstream) {
      try {
          return ImageIO.read(inputstream);
      } catch (Exception e) {
          throw new IllegalStateException("Can't convert to buffered image", e);
      }
  }
  
  public byte[] toByteArray(BufferedImage bufferedImage, String filetype) {
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      try {
          ImageIO.write(bufferedImage, filetype, output);
          return output.toByteArray();
      } catch (Exception e) {
          throw new IllegalStateException(e);
      }
  }
  </code></pre>
  
  <p><strong>Follow up</strong>: is there any library to support compressed PNGs that is written in Java and does not need any native code?</p>