在没有文本的情况下调整照片大小..是否需要 RenderingHints?

发布于 2024-11-18 04:24:55 字数 825 浏览 6 评论 0原文

我正在编写一个快速的小java类,它将图像大小调整为各种较小的尺寸(缩略图大/小/等)。我见过其中包含 RenderingHints 的示例。输出文件比没有时大得多。

我的问题是:如果正在调整大小的图像没有文本,是否有必要使用 RenderingHints?

int IMG_WIDTH = 100;
int IMG_HEIGHT = 100;

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();    
g.setComposite(AlphaComposite.Src);

g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

我从 45kb 图像开始,输出差异是 3kb 文件(不带 RenderingHints)与 24kb 文件(带 RenderingHints)

I am writing a quick little java class that resizes an image into various smaller sizes (thumbnail large/small/etc). I have seen examples that have RenderingHints in it. The output file is significantly larger than without.

My question is: Is it necessary to use RenderingHints if the images that are being resized have no text?

int IMG_WIDTH = 100;
int IMG_HEIGHT = 100;

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();    
g.setComposite(AlphaComposite.Src);

g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

I started with a 45kb image, and the output difference is a 3kb file (without RenderingHints) versus a 24kb file (with RenderingHints)

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

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

发布评论

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

评论(1

痴梦一场 2024-11-25 04:24:55

我想,在阅读以下 stackoverflow.com 问题/答案后:

我是倾向于认为当照片不包含文本时 RenderingHints 不会为我提供任何好处...在这种情况下,没有文本 = 没有 RenderingHints = 较小的调整大小图像

I suppose, after reading the following stackoverflow.com question/answer:

I am inclined to think that RenderingHints will provide no benefit for me when the photos contain no text ... In which case, no text = no RenderingHints = smaller resized image

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