Version: 14Interface: .NETSample Type: SnippetDevelopment Environment: VB.NETKeywords: annotations annotation rotate transform matrix document imaging image mark-upVB.NET Snippet to Rotate annotations in .NET
' This snippet translated from C# to VB by:
' Michael J. Loux Jr - Maine Mutual Group
Private Sub RotateImageAndAnnotation(ByVal angle As Integer, ByVal container As AnnContainer, ByVal viewer As RasterImageViewer)
' Round the angle
angle = angle Mod 360
If angle = 0 Then Exit Sub ' nothing to do
' when we rotate an image, this is what happens:
' 1. The image is rotated around its center (width / 2, height / 2)
' 2. The image is translated so that its top, left position is at 0, 0
'
' To calculate this translation, we:
' 1. Find the 4 end points of the container
' 2. Rotate these points
' 3. Find the minimum/maximum "out of range" point
' 4. Calculate the translation (amount to bring this "out of range" point back into view)
Dim pts As PointF() = { _
New PointF(0, 0), _
New PointF(viewer.Image.ImageWidth, 0), _
New PointF(viewer.Image.ImageWidth, viewer.Image.ImageHeight), _
New PointF(0, viewer.Image.ImageHeight) _
}
Dim origin As New PointF(viewer.Image.ImageWidth / 2, viewer.Image.ImageHeight / 2)
Dim m As New System.Drawing.Drawing2D.Matrix
With m
.RotateAt(angle, origin)
.TransformPoints(pts)
End With
Dim xMin As Single = pts(0).X
Dim yMin As Single = pts(0).Y
Dim i As Integer
For i = 1 To pts.Length - 1
If pts(i).X < xMin Then xMin = pts(i).X
If pts(i).Y < yMin Then yMin = pts(i).Y
Next
Dim xTranslate As Single = -xMin
Dim yTranslate As Single = -yMin
' Now, rotate the image
Dim cmd As New Leadtools.ImageProcessing.RotateCommand
With cmd
.Angle = angle * 100
.Flags = ImageProcessing.RotateCommandFlags.Resize,
.FillColor = RasterColor.FromGdiPlusColor(Color.White)
.Run(viewer.Image)
End With
' Rotate and translate the annotations
Dim obj As AnnObject
For Each obj In container.Objects
obj.Rotate(angle, New AnnPoint(origin))
If xTranslate <> 0 OrElse yTranslate <> 0 Then obj.Translate(xTranslate, yTranslate)
Next
' Reset the container bounds
container.Bounds = New AnnRectangle(0, 0, viewer.Image.ImageWidth, viewer.Image.ImageHeight)
End Sub
If you have any questions about this example, please post them back to this thread. Thanks,
Gabriel
Gabe
Developer Support
LEAD Technologies, Inc.