How to resize an image

How to resize an image

         Before editing an image you need to load your image into cache memory using method Load of the Java class Image. Next, apply Resize method to the image with a new size by selecting new height and width `300x300` in pixels and finally save the result to a file.

Example Java code:

// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir + "aspose-logo.jpg");
image.resize(300, 300);
image.save(dataDir + "SimpleResizing_out.jpg");

         You can make image sizing proportionally the image width or height by specifying the resizing type by selecting `ResizeType.LanczosResample` parameter:

// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java
Image image = Image.load(dataDir + "aspose-logo.jpg");
if (!image.isCached()) {
image.cacheData();
}
// specifying only width and ResizeType
int newWidth = image.getWidth() / 2;
image.resizeWidthProportionally(newWidth, ResizeType.LanczosResample);
// specifying only height and ResizeType
int newHeight = image.getHeight() / 2;
image.resizeHeightProportionally(newHeight, ResizeType.NearestNeighbourResample);
// saving result
image.save(dataDir + "ResizeImageWithResizeTypeEnumeration_out.png");

         The available resize types are listed in the table of the Resize type parameters.