0

我目前正在使用http://code.google.com/p/java-image-scaling/这个库为我的网络应用程序生成缩放图像。但是当我将图像缩小到大约 100x100 大小时,会看到一些剩余的工件在一些图像中。这是抗锯齿的问题吗?以及如何在这个库中使用抗锯齿功能。api 文档没有说明任何内容。

这是代码

File f = new File("C:\\Users\\ad min\\Pictures\\30-whisky-3d-wallpaper-1152x864.jpg");
        BufferedImage src = ImageIO.read(f);

        //ResampleOp resampleOp = new ResampleOp(76, 76);
        ResampleOp resampleOp = new ResampleOp(200,200);
        resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.VerySharp);
        BufferedImage rescaled = resampleOp.filter(src, null);

        ImageIO.write(rescaled, "JPG", new File(
                "C:\\Users\\ad min\\Pictures\\scaleddown.jpg"));

我究竟做错了什么?

4

1 回答 1

0

我终于不需要抗锯齿了

http://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-

compression-quality-when-saving-images-in-java
        Iterator<ImageWriter> iter = ImageIO
                .getImageWritersByFormatName("jpeg");
        ImageWriter writer = (ImageWriter) iter.next();
        // instantiate an ImageWriteParam object with default compression
        // options
        ImageWriteParam iwp = writer.getDefaultWriteParam();
        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwp.setCompressionQuality(1); // an integer between 0 and 1
        // 1 specifies minimum compression and maximum quality
        File file = new File("C:\\Users\\ad min\\Pictures\\scaleddown.jpg");
        FileImageOutputStream output = new FileImageOutputStream(file);
        writer.setOutput(output);
        IIOImage image = new IIOImage(rescaled, null, null);
        writer.write(null, image, iwp);
        writer.dispose();
于 2012-09-08T12:31:59.723 回答