Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Created February 18, 2025 15:59
Show Gist options
  • Save conholdate-gists/7af8e23a65a1b455640a4a7bbf5df138 to your computer and use it in GitHub Desktop.
Save conholdate-gists/7af8e23a65a1b455640a4a7bbf5df138 to your computer and use it in GitHub Desktop.
Resize Images in Java | Change Image Size
// Load image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("aspose-logo.png");
// Cache image data
if (!image.isCached())
{
image.cacheData();
}
// Specify width and height
int newWidth = image.getWidth() / 2;
image.resizeWidthProportionally(newWidth);
int newHeight = image.getHeight() / 2;
image.resizeHeightProportionally(newHeight);
// Save image
image.save("ResizeRasterImage.png");
// Load input vector image
com.aspose.imaging.Image image = com.aspose.imaging.Image.load("image.svg");
// Resize image as PNG
image.resize(image.getWidth() * 10,image.getHeight() * 15);
com.aspose.imaging.imageoptions.PngOptions options = new com.aspose.imaging.imageoptions.PngOptions();
options.setVectorRasterizationOptions(new com.aspose.imaging.imageoptions.SvgRasterizationOptions());
// Save output resized image
image.save("resize.png", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment