Results 1 to 4 of 4

Thread: [2005] Rotating Images Through Graphics

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    29

    [2005] Rotating Images Through Graphics

    I'm using Graphics.DrawImage to draw image files onto a control. This all works fine.

    I wanted to add the ability to rotate the image 90 degrees. The problem that I'm running in to is that you can't just rotate the bounding rectangle (for example, rotating it 90 to the right and putting the Origin at the upper-right) because then it just draws a mirror image, and doesn't actually rotate the image itself.

    My class stores an Origin and a Size. I draw the image in the following way:

    VB Code:
    1. Public Overrides Sub DrawOn(ByRef g As Graphics)
    2.         g.DrawImage(Image, Origin.X, Origin.Y, Size.Width, Size.Height)
    3.     End Sub

    I do the rotation in the following way:

    VB Code:
    1. Public Overrides Sub Rotate(ByVal rotationAngle As Rotations)
    2.         Dim matrix As New Matrix()
    3.         matrix.RotateAt(rotationAngle, CenterPointOfImage)
    4.         Dim ptArray As PointF() = New PointF() {Origin}
    5.         matrix.TransformPoints(ptArray)
    6.         Origin = ptArray(0)
    7.  
    8.         If rotationAngle = Rotations.Right90 Then
    9.             Size = New SizeF(-Size.Height, Size.Width)
    10.         ElseIf rotationAngle = Rotations.Half Then
    11.             Size = New SizeF(-Size.Width, -Size.Height)
    12.         ElseIf rotationAngle = Rotations.Left90 Then
    13.             Size = New SizeF(Size.Height, -Size.Width)
    14.         End If
    15.     End Sub

    So, if I rotate it 90 degrees to the right, it goes from the first image to the second image that I attached.

    Does anyone know if .NET allows you to draw a rotated image and how to do it? Thanks.
    Attached Images Attached Images   
    Last edited by BlueMikey; Jul 26th, 2006 at 01:56 PM. Reason: Made Pics Clearer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width