大家好,我想知道在Java中是否有任何方法可以减小作为BufferedImage加载并将其保存为PNG格式的图像的大小(使用任何类型的压缩)。
也许使用某种png imagewriteparam?但是我没有找到任何有用的东西,所以卡住了。
这里是一个加载和保存图像的示例:
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));
}