Image Editing Tool in VB.Net (Part5- Rotations of Image)

Part1: Open an image

Part2: Resizing image

Part3: Cropping image

Part 4: brightness of image

This article is the next part of how to make an image editor in VB.Net. In this article we will discuss how to rotate and flip an image and save it.

Form Designer:

Put four buttons on the form like this:

Rotations-of-image.jpg

Code:

We are using here the RotateFlip() method for rotaing images. The RotateFlip method accepts the 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 Sub btnRotateLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotateLeft.Click

        PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)

        PictureBox1.Refresh()

    End Sub

 

    Private Sub btnRotateRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotateRight.Click

        PictureBox1.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)

        PictureBox1.Refresh()

    End Sub

 

    Private Sub btnRotateHorizantal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotateHorizantal.Click

        PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)

        PictureBox1.Refresh()

    End Sub

 

    Private Sub btnRotatevertical_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRotatevertical.Click

        PictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipY)

        PictureBox1.Refresh()

    End Sub

If you click on the "horizantal Rotate" button then the result will be like this:


Rotation-of-image.jpg

You can download the source code for description.


One more thing is that the RotateFlip method rotates the image clockwise.


Similar Articles