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));
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…