Making image editing tool in C#-Rotations of an image

this article is the next part of how to make image editor C#.

inthis article we will discuss that how to rotate and flip of an image and save.

Download Source Code

Form Designer:

Put four button on form like this:

Code:

We are using here RotateFlip() method for rotaing images, RotateFlip method accept RotateFlipType enumeration that has these members(Ref: MDSN):

Rotate90FlipNoneSpecifies a 90-degree clockwise rotation without flipping.
Rotate180FlipNoneSpecifies a 180-degree clockwise rotation without flipping.
Rotate270FlipNoneSpecifies a 270-degree clockwise rotation without flipping.
RotateNoneFlipXSpecifies no clockwise rotation followed by a horizontal flip.
Rotate90FlipXSpecifies a 90-degree clockwise rotation followed by a horizontal flip.
Rotate180FlipXSpecifies a 180-degree clockwise rotation followed by a horizontal flip.
Rotate270FlipXSpecifies a 270-degree clockwise rotation followed by a horizontal flip.
RotateNoneFlipYSpecifies no clockwise rotation followed by a vertical flip.
Rotate90FlipYSpecifies a 90-degree clockwise rotation followed by a vertical flip.
Rotate180FlipYSpecifies a 180-degree clockwise rotation followed by a vertical flip.
Rotate270FlipYSpecifies a 270-degree clockwise rotation followed by a vertical flip.
RotateNoneFlipXYSpecifies no clockwise rotation followed by a horizontal and vertical flip.
Rotate90FlipXYSpecifies a 90-degree clockwise rotation followed by a horizontal and vertical flip.
Rotate180FlipXYSpecifies a 180-degree clockwise rotation followed by a horizontal and vertical flip.
Rotate270FlipXYSpecifies a 270-degree clockwise rotation followed by a horizontal and vertical flip.

 

Generate click event of all four button, and try to apply these code snippt

 
   private void btnRotateLeft_Click(object sender, EventArgs e)
        {
            PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
            PictureBox1.Refresh();
        }
 
   private void btnRotateRight_Click(object sender, EventArgs e)
        {
            PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone);
            PictureBox1.Refresh();
        }
 
   private void btnRotateHorizantal_Click(object sender, EventArgs e)
        {
            PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
            PictureBox1.Refresh();
        }
 
    private void btnRotatevertical_Click(object sender, EventArgs e)
        {
            PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY);
            PictureBox1.Refresh();
        }

You can download source code for description.

One more thing that RotateFlip method rotates the image clockwise.


Other related articles of this series:

Making image editing tool in C#

making image editing tool in C#- Resize an image

Making image editing tool in C#- Crop an image

Making image editing tool in C#- Brightness of an image