Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

java - 在Java中调整图像大小(Resizing image in Java)

I have a PNG image and I want to resize it.

(我有一个PNG图片,我想调整其大小。)

How can I do that?

(我怎样才能做到这一点?)

Though I have gone through this I can't understand the snippet.

(虽然我曾经走过这个我无法理解的片段。)

  ask by Suhail Gupta translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

(如果您具有java.awt.Image ,则对其进行大小调整不需要任何其他库。)

Just do:

(做就是了:)

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

Ovbiously, replace newWidth and newHeight with the dimensions of the specified image.

(Ovbiously, 取代 newWidthnewHeight具有指定图像的尺寸。)
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:

(您可以使用以下任何算法:)

See the Javadoc for more info.

(有关更多信息,请参见Javadoc 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...