how to compress a PNG image using Java

Posted by 116213060698242344024 on Stack Overflow See other posts from Stack Overflow or by 116213060698242344024
Published on 2010-04-27T12:55:42Z Indexed on 2010/04/27 19:33 UTC
Read the original article Hit count: 146

Filed under:
|
|

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.

Maybe some sort of png imagewriteparam? I didnt find anything helpful so im stuck.

heres a sample how the image is loaded and saved

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));
}

© Stack Overflow or respective owner

Related posts about java

Related posts about png