How to rotate an image
How to rotate an image
Rotate and flip an image
Rotating an image with a fixed angle of 90/180/270-degree with or without a flip can be done with RotateFlip method. You need to pass a rotate type parameter to the method. In the Java code example below we use the type `Rotate270FlipNone`:
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java | |
// loading an Image | |
Image image = Image.load(dataDir + "aspose-logo.jpg"); | |
// Rotating Image | |
image.rotateFlip(RotateFlipType.Rotate270FlipNone); | |
image.save(dataDir + "RotatingAnImage_out.jpg"); |
Please refer to the Rotate and flip types parameters list for available rotating types.
Rotate an image to the specific angle
Additionally, you can rotate an image to a specific angle with Rotate method. For clockwise rotation, the rotation angle value should be positive and for the opposite direction - negative. Also, you can use Rotate method with additional parameters. `Resize proportionally` boolean parameter indicates whether the resulting image resizes proportionally or not. Otherwise, empty corners will appear after the image was rotated and you need to indicate the background color to fill the corners.
// For complete examples and data files, please go to https://github.com/Muhammad-Adnan-Ahmad/Aspose.Imaging-for-Java | |
RasterImage image = (RasterImage) Image.load(dataDir + "aspose-logo.jpg"); | |
// Before rotation, the image should be cached for better performance | |
if (!image.isCached()) { | |
image.cacheData(); | |
} | |
// Perform the rotation on 20 degree while keeping the image size | |
image.rotate(20f); | |
// Save the result to a new file | |
image.save(dataDir + "RotatingImageOnSpecificAngle_out.jpg"); |