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.
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):
Rotate90FlipNone | Specifies a 90-degree clockwise rotation without flipping. |
Rotate180FlipNone | Specifies a 180-degree clockwise rotation without flipping. |
Rotate270FlipNone | Specifies a 270-degree clockwise rotation without flipping. |
RotateNoneFlipX | Specifies no clockwise rotation followed by a horizontal flip. |
Rotate90FlipX | Specifies a 90-degree clockwise rotation followed by a horizontal flip. |
Rotate180FlipX | Specifies a 180-degree clockwise rotation followed by a horizontal flip. |
Rotate270FlipX | Specifies a 270-degree clockwise rotation followed by a horizontal flip. |
RotateNoneFlipY | Specifies no clockwise rotation followed by a vertical flip. |
Rotate90FlipY | Specifies a 90-degree clockwise rotation followed by a vertical flip. |
Rotate180FlipY | Specifies a 180-degree clockwise rotation followed by a vertical flip. |
Rotate270FlipY | Specifies a 270-degree clockwise rotation followed by a vertical flip. |
RotateNoneFlipXY | Specifies no clockwise rotation followed by a horizontal and vertical flip. |
Rotate90FlipXY | Specifies a 90-degree clockwise rotation followed by a horizontal and vertical flip. |
Rotate180FlipXY | Specifies a 180-degree clockwise rotation followed by a horizontal and vertical flip. |
Rotate270FlipXY | Specifies 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