调整大小后的图像质量会下降

发布于 2024-08-23 20:34:33 字数 313 浏览 1 评论 0原文

我使用 Java2D Graphics 类调整图像大小。但看起来不太对劲。

    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();

是否可以在不引入伪影的情况下缩放图像?

I resized an image using Java2D Graphics class. But it doesn't look right.

    BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
    Graphics2D g = resizedImage.createGraphics();
    g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
    g.dispose();

Is it possible to scale an image without introducing artifacts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

怪我入戏太深 2024-08-30 20:34:33

一般来说,位图图形不能很好地缩放。当您增加图像尺寸时,退化尤其明显,但即使缩小也可能会引入不良的伪像,尤其是在不按积分因子缩放的情况下。

如果您需要显示多个尺寸的单个图像,最好的解决方案是使用矢量*图形采用您拥有的最高保真度位图并按积分因子缩小。

*请注意,矢量图形不适用于照片等。

Bitmap graphics do not scale well, generally speaking. Degradation is particularly notable when you increase the size of the image, but even scaling down can introduce undesirable artifacts especially if not scaling by integral factors.

The best solution, if you need multiple sizes of a single image for display, is to either use vector* graphics or take the highest fidelity bitmap you have and scale down, and by integral factors.

*Note that vector graphics aren't an option for photographs and the like.

雾里花 2024-08-30 20:34:33

这篇 Chris Campbell 撰写的文章< /a> 有很多关于使用 Java2D 缩放图像的详细信息。

关于缩放的质量,您可以使用许多选项,通常质量越好,缩放所需的时间就越长(性能与质量的权衡)。

本文中的信息可能会帮助您的缩放看起来更好,但正如 @Kevin 在他的回答中所说,最终没有任何缩放会是绝对完美的。

This article by Chris Campbell has lots of detailed information on scaling images with Java2D.

There are a number of options you can use regarding the quality of the scaling, where generally the better the quality the longer the scaling will take (performance versus quality tradeoff).

The information in the article will probably help your scaling look better, but as @Kevin says in his answer, at the end of the day no scaling is going to be absolutely perfect.

£冰雨忧蓝° 2024-08-30 20:34:33

您可以查看 java-image-scaling 库。通过快速测试,它创建了比使用标准 Java2D/AWT 工具质量更好的缩小图像。

You could look into java-image-scaling library. With a quick test it created a better quality down scaled image than using standard Java2D/AWT tools.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文