Created
February 18, 2025 15:59
-
-
Save conholdate-gists/7af8e23a65a1b455640a4a7bbf5df138 to your computer and use it in GitHub Desktop.
Resize Images in Java | Change Image Size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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