title: Rotating an Image in a picture box
body: <p>I am currently writing a game which uses an arrow which needs to rotate in order to tell the user at what angle they will "throw" their boule. I have coded almost all of the solution however, I have the arrow as a picture box and an image inside of it. I need to be able to rotate in and record at what angle it has been rotated, I have a timer which I plan to rotate the image one degree each time it ticks and add one to the angle variable. The only thing I struggle with is actually rotating the image. Any further details you require I can give, </p>
  
  <p>Any help is much appreciated,
  Many Thanks,
  Dan</p>
  
  <pre><code>Private Function RotateImage(image As Image, angle As Single) As Bitmap
      ' the calling code is responsible for (and must) 
      ' disposing of the bitmap returned
  
      Dim retBMP As New Bitmap(image)
      retBMP.SetResolution(image.HorizontalResolution, image.VerticalResolution)
  
      Using g = Graphics.FromImage(retBMP)
          ' rotate aroung the center of the image
          g.TranslateTransform(image.Width \ 2, image.Height \ 2)
  
          'rotate
          g.RotateTransform(angle)
  
          g.TranslateTransform(-image.Width \ 2, -image.Height \ 2)
  
          'draw image to the new boitmap
          g.DrawImage(retBMP, New PointF(0, 0))
      End Using
      Return retBMP
  End Function
  
  
  Private Sub PowerTimer_Tick(sender As Object, e As EventArgs) Handles PowerTimer.Tick
  
      If ArrowAngle &gt;= 45 Then
          AngleIncreasing = False
      ElseIf ArrowAngle &lt;= -45 Then
          AngleIncreasing = True
      End If
      If AngleIncreasing = True Then
          Arrow.Image = New Bitmap(Arrow.Image)
          Arrow.Image = RotateImage(Arrow.Image, 1)
          Me.Refresh()
          ArrowAngle = ArrowAngle + 1
      Else
          Arrow.Image = RotateImage(Arrow.Image, 1)
          Arrow.Image = RotateImage(Arrow.Image, -1)
          Me.Refresh()
          ArrowAngle = ArrowAngle - 1
      End If
  End Sub
  </code></pre>