Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java图像缩放可以提高质量吗?_Java_Image_Scaling - Fatal编程技术网

Java图像缩放可以提高质量吗?

Java图像缩放可以提高质量吗?,java,image,scaling,Java,Image,Scaling,我目前正在使用以下代码缩放图像 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

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

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

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

试试。

您可能想看看这个。它有双三次和Lanczos等算法,还有一个反锐化过滤器。

您可以使用

也试试这个


还可以试试library

您可以查看上的
缩放*
字段,我认为这会有所帮助。我已经详细回答了您的问题:使用java图像缩放库获得了最佳效果。
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()));
}