Lethal Left Eye
Lethal Left Eye

Reputation: 378

Rotate an image by 15 degrees increments?

I'm faced with what seems to be a very daunting task. I need to rotate an image, within a PictureBox, in increments of 15 degrees. After quite some time spent searching the depths of the internet, I've not found anything to achieve this task. The closest thing I could come up with was a 90 degree flip using:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    InitializeBitmap()
End Sub

Dim bitmap1 As Bitmap

Private Sub InitializeBitmap()
    Try
        bitmap1 = CType(Bitmap.FromFile("G:\Documents\Dawson\Semster 3\Visual Basic I\Test\subs\subs\Wheel.bmp"), Bitmap)
        PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
        PictureBox1.Image = bitmap1
    Catch ex As System.IO.FileNotFoundException
        MessageBox.Show("There was an error. Check the path to the bitmap.")
    End Try
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    If bitmap1 IsNot Nothing Then
        bitmap1.RotateFlip(RotateFlipType.Rotate90FlipXY)
        PictureBox1.Image = bitmap1
    End If
End Sub

I'm in need of code that will flip my image by 15 degree increments; nothing more, and nothing less.

Anyone willing to provide this code to me would be greatly appreciated. Thanks for your time.

Upvotes: 1

Views: 8287

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564403

Here is a CodeProject article showing how to rotate an image in a PictureBox.

The basic approach requires using GDI and the Graphics class to get the image, perform the rotation (via methods like Graphics.RotateTransform), then save the results as an image, and assign it to your PictureBox control.

Upvotes: 3

Related Questions