如何使用Java压缩PNG图像 [英] how to compress a PNG image using Java

查看:1635
本文介绍了如何使用Java压缩PNG图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想知道,如果有任何方式在Java中减少图像的大小(使用任何类型的压缩)作为一个BufferedImage加载并将被保存为PNG。

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.

也许是某种png imagewriteparam?

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


推荐答案

a href =https://github.com/depsypher/pngtastic/ =nofollow> pngtastic 。这是一个纯java的图像优化器,可以缩小png图像在一定程度上。

You may want to try pngtastic. It's a pure java png image optimizer that can shrink may png images down to some degree.

这篇关于如何使用Java压缩PNG图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆