[FIXED] Resizing image in Java

Issue

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.

Solution

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

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

Obviously, replace newWidth and newHeight with the dimensions of the specified image.
Notice the last parameter: it tells 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.

Answered By – Alba Mendez

Answer Checked By – Timothy Miller (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published