在java中调整图像大小 [英] resizing image in 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
:使用默认的图像缩放算法。 -
Image.SCALE_FAST
:选择图像缩放算法,该算法比缩放图像的平滑度具有更高的缩放速度优先级。 -
Image.SCALE_AREA_AVERAGING
:使用Area Averaging图像缩放算法。
Image.SCALE_REPLICATE
:使用ReplicateScaleFilter
类中包含的图像缩放算法。
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 theReplicateScaleFilter
class.
参见 Javadoc 获取更多信息。
这篇关于在java中调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!