title: how to compress a PNG image using Java
body: <p>Hi I would like to know if there is any way in Java to reduce the size of an image (use any kind of compression) that was loaded as a BufferedImage and is going to be saved as an PNG.</p>
  
  <p>Maybe some sort of png imagewriteparam? I didnt find anything helpful so im stuck.</p>
  
  <p>heres a sample how the image is loaded and saved</p>
  
  <pre><code>public static BufferedImage load(String imageUrl) {         
      Image image = new ImageIcon(imageUrl).getImage();
      bufferedImage = new BufferedImage(image.getWidth(null),
                                                      image.getHeight(null),
                                                      BufferedImage.TYPE_INT_ARGB);
      Graphics2D g2D = bufferedImage.createGraphics();
      g2D.drawImage(image, 0, 0, null);
      return bufferedImage;
  }
  
  public static void storeImageAsPng(BufferedImage image, String imageUrl) throws IOException {
      ImageIO.write(image, "png", new File(imageUrl));
  }
  </code></pre>