在 Java 中调整图像大小 [英] Resizing image in Java

查看:44
本文介绍了在 Java 中调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 PNG 图片,我想调整它的大小.我怎样才能做到这一点?虽然我已经经历了这个我看不懂片段.

I have a PNG image and I want to resize it. How can I do that? Though I have gone through this I can't understand the snippet.

推荐答案

如果你有一个 java.awt.Image,重新调整它不需要任何额外的库.就这样做:

If you have an java.awt.Image, rezising it doesn't require any additional libraries. Just do:

Image newImage = yourImage.getScaledInstance(newWidth, newHeight, Image.SCALE_DEFAULT);

显然,替换 newWidthnewHeight 为指定图像的尺寸.
请注意最后一个参数:它告诉运行时您要用于调整大小的算法.

Ovbiously, replace newWidth and newHeight with the dimensions of the specified image.
Notice the last parameter: it tells to the runtime the algorithm you want to use for resizing.

有些算法可以产生非常精确的结果,但是这些算法需要很长时间才能完成.
您可以使用以下任何一种算法:

There are algorithms that produce a very precise result, however these take a large time to complete.
You can use any of the following algorithms:

  • Image.SCALE_DEFAULT: Use the default image-scaling algorithm.
  • Image.SCALE_FAST: Choose an image-scaling algorithm that gives higher priority to scaling speed than smoothness of the scaled image.
  • Image.SCALE_SMOOTH: Choose an image-scaling algorithm that gives higher priority to image smoothness than scaling speed.
  • Image.SCALE_AREA_AVERAGING: Use the Area Averaging image scaling algorithm.
  • Image.SCALE_REPLICATE: Use the image scaling algorithm embodied in the ReplicateScaleFilter class.

请参阅Javadoc 了解更多信息.

See the Javadoc for more info.

这篇关于在 Java 中调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆