Welcome Guest! To enable all features, please Login or Register.



Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, August 16, 2005 1:12:40 PM(UTC)


Groups: Registered, Tech Support
Posts: 46

Version: 14
Interface: .NET
Sample Type: Snippet
Development Environment: VB.NET
Keywords: annotations annotation rotate transform matrix document imaging image mark-up

VB.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)


    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



    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)


    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)



    ' 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,



Developer Support
LEAD Technologies, Inc.


Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.071 seconds.