使用Java将1000像素的图像调整为200像素时质量更好的图像

问题描述 投票:0回答:1

我必须将Java中的图像大小从大约1000px调整为200px,然后将它们复制到Web文件夹,以200px的分辨率显示在HTML报告中。 (请注意,我必须创建这些文件,因为原始图像将无法用于网络服务器,并且仅复制原始图像将需要太多空间。)

尽管原始图像质量通常很高,但200px图像可能有点颗粒感,我可以调整下面的代码以产生更好质量的图像吗?>

public static BufferedImage resizeUsingImageIO(Image srcImage, int size)
    {
        int w = srcImage.getWidth(null);
        int h = srcImage.getHeight(null);

        // Determine the scaling required to get desired result.
        float scaleW = (float) size / (float) w;
        float scaleH = (float) size / (float) h;

        MainWindow.logger.finest("Image Resizing to size:" + size + " w:" + w + ":h:" + h + ":scaleW:" + scaleW + ":scaleH" + scaleH);

        //Create an image buffer in which to paint on, create as an opaque Rgb type image, it doesn't matter what type
        //the original image is we want to convert to the best type for displaying on screen regardless
        BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);

        // Set the scale.
        AffineTransform tx = new AffineTransform();
        tx.scale(scaleW, scaleH);

        // Paint image.
        Graphics2D g2d = bi.createGraphics();
        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, size, size);
        g2d.setComposite(AlphaComposite.SrcOver);
        g2d.drawImage(srcImage, tx, null);
        g2d.dispose();
        return bi;

我必须将Java中的图像大小从大约1000px调整为200px,然后将它们复制到Web文件夹,以200px的分辨率显示在HTML报告中。 (请注意,我必须创建这些文件,因为...

java bufferedimage java-2d
1个回答
0
投票

您可以通过打开抗锯齿来提高质量。您的情况是:

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.