This quick tutorial explains how to rotate image in C# with the help of configuration settings and a step-by-step list of tasks to achieve this functionality. While using C# rotate bitmap operation will be demonstrated for the user-specified angle along with the option to set the background color of the surface exposed due to the image rotation. You will also learn to rotate and flip images simultaneously for any type of image like BMP, PNG, JPEG, etc.
Steps to Rotate Image in C#
- Establish the environment to add Aspose.Imaging from the Nuget package manager to the application
- Load the source image into the Image class object that is to be rotated
- Cast the image to RasterImage
- Cache the image into the memory to get better performance during transformations
- Rotate the image at 30 degrees and set the background color to Green using RasterImage.Rotate function
- Flip the image on Y-Axis using RasterImage.RotateFlip function
- Save the modified image as BMP
By using C# rotate image by angle operation is described in detail with the help of environment configuration and then a sequence of steps to be performed for this feature. The target BMP image is loaded as the RasterImage that has different methods to rotate and flip the images. The image is first cached to gain performance and then rotated and flipped before saving it back on the disk.
Code to Rotate Image in C#
To rotate bitmap C# code is demonstrated that uses RasterImage.Rotate function to just rotate the image at a certain angle. You can set the background color for the space that will be left blank in case of rotating the source image. Additionally, you can flip the image also with the help of RasterImage.RotateFlip function that requires RotateFlipType enumerator containing values like Rotate90FlipX to rotate at 90 degrees and then flip around the X-Axis, Rotate90FlipY to rotate at 90 degrees and flip around Y-Axis and similarly having 16 different options to rotate and flip.
In this tutorial, we have learned how to rotate image in C# however, if you want to learn how to resize images, refer to the article on how to resize image in C#.