【问题标题】:Java image scaling improve quality?Java图像缩放提高质量?
【发布时间】:2013-04-12 15:44:32
【问题描述】:

我目前正在使用以下代码缩放图像。

Image scaledImage = img.getScaledInstance( width, int height, Image.SCALE_SMOOTH);
BufferedImage imageBuff = new BufferedImage(width, scaledImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = imageBuff.createGraphics();
g.drawImage(scaledImage, 0, 0, new Color(0, 0, 0), null);
g.dispose();
ImageIO.write(imageBuff, "jpg", newFile);

任何人都知道一种更好的方法来缩放图像并获得更好的质量结果,或者甚至对改进我当前的代码以获得更好的质量输出有任何帮助。

【问题讨论】:

标签: java image scaling


【解决方案1】:

您可以使用Affine Transorm

public static BufferedImage getScaledImage(BufferedImage image, int width, int height) throws IOException {
    int imageWidth  = image.getWidth();
    int imageHeight = image.getHeight();

    double scaleX = (double)width/imageWidth;
    double scaleY = (double)height/imageHeight;
    AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
    AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);

    return bilinearScaleOp.filter(
        image,
        new BufferedImage(width, height, image.getType()));
}

也试试这个Example

也可以试试java-image-scaling

【讨论】:

  • 使用 java-image-scaling 库获得了最好的结果。
【解决方案2】:

你可能想看看这个image scaling library。它有双三次和 Lanczos 等算法,还有一个非锐化滤波器。

【讨论】:

    【解决方案3】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-11
      • 2010-09-19
      • 2010-09-26
      • 2014-04-07
      • 2016-12-09
      • 2011-10-11
      • 1970-01-01
      相关资源
      最近更新 更多