在java中调整图像大小 [英] resizing image in java

查看:266
本文介绍了在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 cant understand the snippet.

推荐答案

如果您有图像,重新确定它不需要任何其他库。只需这样做:

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

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

奇怪的是,替换 newWidth newHeight 带有指定图像的尺寸。

注意最后一个参数:它告诉运行时算法你想用来调整大小。

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 获取更多信息。

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

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