2 Attachment(s)
[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:
Public Overrides Sub DrawOn(ByRef g As Graphics)
g.DrawImage(Image, Origin.X, Origin.Y, Size.Width, Size.Height)
End Sub
I do the rotation in the following way:
VB Code:
Public Overrides Sub Rotate(ByVal rotationAngle As Rotations)
Dim matrix As New Matrix()
matrix.RotateAt(rotationAngle, CenterPointOfImage)
Dim ptArray As PointF() = New PointF() {Origin}
matrix.TransformPoints(ptArray)
Origin = ptArray(0)
If rotationAngle = Rotations.Right90 Then
Size = New SizeF(-Size.Height, Size.Width)
ElseIf rotationAngle = Rotations.Half Then
Size = New SizeF(-Size.Width, -Size.Height)
ElseIf rotationAngle = Rotations.Left90 Then
Size = New SizeF(Size.Height, -Size.Width)
End If
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.
Re: [2005] Rotating Images Through Graphics
Re: [2005] Rotating Images Through Graphics
Oh wow, didn't even think those points would have a different effect. That is a huge help. Thank you very much.
Re: [2005] Rotating Images Through Graphics
your welcome.
Don't forget to mark your thread resolved in the thread tools.