2

我正在使用 JMagick 用 Ja​​va 编写程序,我需要能够通过降低图像质量来压缩图像(降低文件大小)。我尝试了 info.setQuality(99) 和 info.setQuality(1) 类,但输出文件的大小没有区别。

有没有办法提高和降低图像的质量,从而用 JMagick 调整输出文件的文件大小?

提前致谢。抱歉格式不好。

    import java.io.*;
    import magick.*;
    public class jpgconverter {
    /**
     * @param args
     * @throws MagickException 
     * @throws IOException 
     */
    public static void main(String[] args) throws MagickException, IOException {
    int pixels = 500;
    ImageInfo info = new ImageInfo("/home/bram/Downloads/verborgenlagen.jpg");
        MagickImage converter = new MagickImage(info);
        double currentHeight = converter.getDimension().getHeight();
        double currentWidth = converter.getDimension().getWidth();
        if(currentWidth > currentHeight) {
            currentHeight = currentHeight * pixels / currentWidth;
            currentWidth = pixels;
        }else {
            if(currentHeight > currentWidth) {
                currentWidth = currentWidth * pixels / currentHeight;
                currentHeight = pixels;
            }
        }
        converter.setXResolution(72.00);
        converter.setYResolution(72.00);
    converter = converter.scaleImage((int)currentWidth, (int)currentHeight);
    converter.setFileName("/home/bram/Downloads/verborgenlagenConverted.jpg");
    converter.writeImage(info);
    }
}
4

0 回答 0