This quick tutorial is designed to explain how to resize image using Java with the help of a sequence of steps and a runnable sample code. To resize image Java code demonstrates the process by setting a new size and resize type however you can utilize a lot of other options also. The output image can be saved in any format like JPEG, PNG, BMP, etc.
Steps to Resize Image using Java
- Configure the application to use Aspose.Imaging from the Maven repository
- Load the source image from the disk into the Image class object
- Call Image.resize() function by providing new size and ResizeType
- Save the output image on disk in the desired format
While using Java resize image process is described here by first sharing the steps to configure the environment and then a step-by-step procedure to be followed in the Java program. The Image class contains a number of overloads for the resize() function that provides different options to resize the image using ResizeType or ImageResizeSettings enumerator. Similarly, the save() method has multiple options to save the output image to a stream or on the disk along with setting the bounding rectangle.
Code to Resize Image using Java
This code demonstrates how using Java resize image file can be managed by using any of resizing types specified in ResizeType enumerator including Bell, CatmullRom, CubicBSpline, HighQualityResample, LanczosResample, etc. Similarly, you can set the color quantization method value, the type of the filter and the interpolation mode as well using the ImageResizeSettings object in the resize() function.
This quick guide has taught us how using Java resize image without losing quality. If you want to learn the conversion between different image types like BMP to PNG, refer to the article on how to convert BMP to PNG in Java.