Leadtools.Annotations Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 15.10.31
AnnTransformer Class
See Also  Members   Example 
Leadtools.Annotations Namespace : AnnTransformer Class




The AnnTransformer class is an Annotation support class which provides functionality for converting annotation points, rectangles, lengths, etc. from one coordinate system to another.

Object Model


Syntax

Visual Basic (Declaration) 
<SerializableAttribute()>
Public Class AnnTransformer 
   Inherits Transformer
Visual Basic (Usage)Copy Code
Dim instance As AnnTransformer
C# 
[SerializableAttribute()]
public class AnnTransformer : Transformer 
Managed Extensions for C++ 
[SerializableAttribute()]
public __gc class AnnTransformer : public Transformer 
C++/CLI 
[SerializableAttribute()]
public ref class AnnTransformer : public Transformer 

Example

This example converts an annotation's point, length, size and rectangle from one unit of measure to another.

Visual BasicCopy Code
Public Sub AnnTransformer_AnnTransformer()
   ' set up a new unit converter with 96 DPI
   Dim converter As AnnUnitConverter = New AnnUnitConverter(96, 96)
   ' set up a new matrix, scale it by 2,2 around the origin
   Dim transform As Matrix = New Matrix()
   transform.Scale(2, 2)

   ' set up the AnnTransformer
   Dim transformer As AnnTransformer = New AnnTransformer(converter, transform)

   ' declare a new AnnPoint at 4, 5 inches
   ' transform it to physical coordinate using the transformer and show it in pixels
   ' then transform it back to its original logical coordinates
   Console.WriteLine("Point{0}--------", Environment.NewLine)

   Dim pt1 As AnnPoint = New AnnPoint(4, 5, AnnUnit.Inch)
   PrintOut(converter, " Original: ", pt1)

   Dim pt2 As AnnPoint = transformer.PointToPhysical(pt1)
   PrintOut(converter, " Physical: ", pt2)

   Dim pt3 As AnnPoint = transformer.PointToLogical(pt2)
   PrintOut(converter, " Logical : ", pt3)

   ' declare an array of AnnPoints, do the same
   Console.WriteLine("Points{0}--------", Environment.NewLine)

   Dim pts1() As AnnPoint = _
{ _
   New AnnPoint(4, 5, AnnUnit.Inch), _
   New AnnPoint(5.2F, 3, AnnUnit.Inch), _
   New AnnPoint(2, 7.83F, AnnUnit.Inch) _
}


   PrintOut(converter, " Original: ", pts1)

   Dim pts2 As AnnPoint() = transformer.PointToPhysical(pts1)
   PrintOut(converter, " Physical: ", pts2)

   Dim pts3 As AnnPoint() = transformer.PointToLogical(pts2)
   PrintOut(converter, " Logical : ", pts3)

   ' declare a rectangle, do the same
   Console.WriteLine("Rectangle{0}--------", Environment.NewLine)

   Dim rc1 As AnnRectangle = New AnnRectangle(2, 3, 4, 1, AnnUnit.Inch)
   PrintOut(converter, " Original: ", rc1)

   Dim rc2 As AnnRectangle = transformer.RectangleToPhysical(rc1)
   PrintOut(converter, " Physical: ", rc2)

   Dim rc3 As AnnRectangle = transformer.RectangleToLogical(rc2)
   PrintOut(converter, " Logical : ", rc3)

   ' declare a length, do the same
   Console.WriteLine("Length{0}--------", Environment.NewLine)

   Dim l1 As AnnLength = New AnnLength(10.5F, AnnUnit.Inch)
   PrintOut(converter, " Original: ", l1)

   Dim l2 As AnnLength = transformer.LengthToPhysical(l1)
   PrintOut(converter, " Physical: ", l2)

   Dim l3 As AnnLength = transformer.LengthToLogical(l2)
   PrintOut(converter, " Logical : ", l3)

   transform.Dispose()
End Sub

Private Sub PrintOut(ByVal converter As AnnUnitConverter, ByVal text As String, ByVal pt As AnnPoint)
   Console.WriteLine("{0}{1}({2})", text, pt.ConvertTo(converter, AnnUnit.Inch), pt.ConvertTo(converter, AnnUnit.Pixel))
End Sub

Private Sub PrintOut(ByVal converter As AnnUnitConverter, ByVal text As String, ByVal pts As AnnPoint())
   Console.WriteLine(text)

   Dim i As Integer = 0
   Do While i < pts.Length
      Console.WriteLine(" {0}. {1}({2})", i, pts(i).ConvertTo(converter, AnnUnit.Inch), pts(i).ConvertTo(converter, AnnUnit.Pixel))
      i += 1
   Loop
End Sub

Private Sub PrintOut(ByVal converter As AnnUnitConverter, ByVal text As String, ByVal rc As AnnRectangle)
   Console.WriteLine("{0}{1}({2})", text, rc.ConvertTo(converter, AnnUnit.Inch), rc.ConvertTo(converter, AnnUnit.Pixel))
End Sub

Private Sub PrintOut(ByVal converter As AnnUnitConverter, ByVal text As String, ByVal ln As AnnLength)
   Console.WriteLine("{0}{1}({2})", text, New AnnLength(ln.Converted(converter, AnnUnit.Inch), AnnUnit.Inch), New AnnLength(ln.Converted(converter, AnnUnit.Pixel), AnnUnit.Pixel))
End Sub
C#Copy Code
public void AnnTransformer_AnnTransformer() 

   // set up a new unit converter with 96 DPI 
   AnnUnitConverter converter = new AnnUnitConverter(96, 96); 
   // set up a new matrix, scale it by 2,2 around the origin 
   Matrix transform = new Matrix(); 
   transform.Scale(2, 2); 
 
   // set up the AnnTransformer 
   AnnTransformer transformer = new AnnTransformer(converter, transform); 
 
   // declare a new AnnPoint at 4, 5 inches 
   // transform it to physical coordinate using the transformer and show it in pixels 
   // then transform it back to its original logical coordinates 
   Console.WriteLine("Point{0}--------", Environment.NewLine); 
 
   AnnPoint pt1 = new AnnPoint(4, 5, AnnUnit.Inch); 
   PrintOut(converter, "  Original: ", pt1); 
 
   AnnPoint pt2 = transformer.PointToPhysical(pt1); 
   PrintOut(converter, "  Physical: ", pt2); 
 
   AnnPoint pt3 = transformer.PointToLogical(pt2); 
   PrintOut(converter, "  Logical : ", pt3); 
 
   // declare an array of AnnPoints, do the same 
   Console.WriteLine("Points{0}--------", Environment.NewLine); 
 
   AnnPoint[] pts1 = 

   new AnnPoint(4, 5, AnnUnit.Inch), 
   new AnnPoint(5.2f, 3, AnnUnit.Inch), 
   new AnnPoint(2, 7.83f, AnnUnit.Inch), 
}; 
 
   PrintOut(converter, "  Original: ", pts1); 
 
   AnnPoint[] pts2 = transformer.PointToPhysical(pts1); 
   PrintOut(converter, "  Physical: ", pts2); 
 
   AnnPoint[] pts3 = transformer.PointToLogical(pts2); 
   PrintOut(converter, "  Logical : ", pts3); 
 
   // declare a rectangle, do the same 
   Console.WriteLine("Rectangle{0}--------", Environment.NewLine); 
 
   AnnRectangle rc1 = new AnnRectangle(2, 3, 4, 1, AnnUnit.Inch); 
   PrintOut(converter, "  Original: ", rc1); 
 
   AnnRectangle rc2 = transformer.RectangleToPhysical(rc1); 
   PrintOut(converter, "  Physical: ", rc2); 
 
   AnnRectangle rc3 = transformer.RectangleToLogical(rc2); 
   PrintOut(converter, "  Logical : ", rc3); 
 
   // declare a length, do the same 
   Console.WriteLine("Length{0}--------", Environment.NewLine); 
 
   AnnLength l1 = new AnnLength(10.5f, AnnUnit.Inch); 
   PrintOut(converter, "  Original: ", l1); 
 
   AnnLength l2 = transformer.LengthToPhysical(l1); 
   PrintOut(converter, "  Physical: ", l2); 
 
   AnnLength l3 = transformer.LengthToLogical(l2); 
   PrintOut(converter, "  Logical : ", l3); 
 
   transform.Dispose(); 

 
private void PrintOut(AnnUnitConverter converter, string text, AnnPoint pt) 

   Console.WriteLine("{0}{1}({2})", 
      text, 
      pt.ConvertTo(converter, AnnUnit.Inch), 
      pt.ConvertTo(converter, AnnUnit.Pixel)); 

 
private void PrintOut(AnnUnitConverter converter, string text, AnnPoint[] pts) 

   Console.WriteLine(text); 
 
   for(int i = 0; i < pts.Length; i++) 
   { 
      Console.WriteLine("    {0}. {1}({2})", 
         i, 
         pts[i].ConvertTo(converter, AnnUnit.Inch), 
         pts[i].ConvertTo(converter, AnnUnit.Pixel)); 
   } 

 
private void PrintOut(AnnUnitConverter converter, string text, AnnRectangle rc) 

   Console.WriteLine("{0}{1}({2})", 
      text, 
      rc.ConvertTo(converter, AnnUnit.Inch), 
      rc.ConvertTo(converter, AnnUnit.Pixel)); 

 
private void PrintOut(AnnUnitConverter converter, string text, AnnLength ln) 

   Console.WriteLine("{0}{1}({2})", 
      text, 
      new AnnLength(ln.Converted(converter, AnnUnit.Inch), AnnUnit.Inch), 
      new AnnLength(ln.Converted(converter, AnnUnit.Pixel), AnnUnit.Pixel)); 
}

Remarks

This class derives from the Transformer class and provides extra functionality to deal with annotation-specific objects. The units of measure are taken into consideration and transformed objects retain the same units as the originals.

Inheritance Hierarchy

System.Object
   Leadtools.Transformer
      Leadtools.Annotations.AnnTransformer

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Leadtools.Annotations requires a Document or Medical toolkit license and unlock key. For more information, refer to: Raster Pro/Document/Medical Features