[英]Java image scaling improve quality?
I am currently scaling images using the following code.我目前正在使用以下代码缩放图像。
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);
Anyone have an idea of a better way of scaling an image and getting better quality results, or even any help on improving my current code to get better quality output.任何人都有一个更好的方法来缩放图像并获得更好质量的结果,甚至对改进我当前的代码以获得更好质量的输出有任何帮助。
You can use 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()));
}
Also try this Example .也试试这个 例子。
Also Try java-image-scaling library还可以尝试java-image-scaling库
You might want to look at this image scaling library .你可能想看看这个图像缩放库。 It has algorithms like bicubic and Lanczos and also an unsharp filter.它有像 bicubic 和 Lanczos 这样的算法,还有一个 unsharp 过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.