Created
May 16, 2025 10:17
-
-
Save conholdate-gists/fc528e3daab29af89a03832c6080d645 to your computer and use it in GitHub Desktop.
Crop Image in Java | Crop JPG PNG BMP TIFF any Picture
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 the image. | |
com.aspose.imaging.RasterImage rasterImage = (com.aspose.imaging.RasterImage)com.aspose.imaging.Image.Load("image.png"); | |
// Before cropping, the image should be cached for better performance. | |
if (!rasterImage.isCached()) | |
{ | |
rasterImage.cacheData(); | |
} | |
// Create an instance of Rectangle class with desired size and crop the image. | |
com.aspose.imaging.Rectangle rect = new com.aspose.imaging.Rectangle(20, 20, 20, 20); | |
rasterImage.crop(rect); | |
// Save cropped image. | |
rasterImage.save("cropped.png"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment