Leadtools.Annotations Requires Document/Medical product license | Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
ConvertObjectToLogicalPoints Method
See Also  Example
Leadtools.Annotations Namespace > AnnObject Class : ConvertObjectToLogicalPoints Method



points
A an array points in object coordinates.
points
A an array points in object coordinates.
Converts an array of points from object to logical coordinates.

Syntax

Visual Basic (Declaration) 
Public Function ConvertObjectToLogicalPoints( _
   ByVal points() As AnnPoint _
) As AnnPoint()
Visual Basic (Usage)Copy Code
Dim instance As AnnObject
Dim points() As AnnPoint
Dim value() As AnnPoint
 
value = instance.ConvertObjectToLogicalPoints(points)
C# 
public AnnPoint[] ConvertObjectToLogicalPoints( 
   AnnPoint[] points
)
C++/CLI 
public:
array<AnnPoint>^ ConvertObjectToLogicalPoints( 
   array<AnnPoint>^ points
) 

Parameters

points
A an array points in object coordinates.

Return Value

An array of points containing the result in logical coordinates.

Example

This example will burn all lines and rectangle objects to the image in an automation mode

Visual BasicCopy Code
Private Sub BurnAllLinesAndRectanglesToImage(ByVal automation As AnnAutomation)
   ' Create a Graphics object from the RasterImage we are annotating
   Dim hdc As IntPtr = automation.Viewer.Image.CreateLeadDC()
   Using g As Graphics = Graphics.FromHdc(hdc)
      ' Loop through all the objects in the annotation container
      For Each annObj As AnnObject In automation.Container.Objects
         If (TypeOf annObj Is AnnLineObject) Then
            Dim lineObj As AnnLineObject = DirectCast(annObj, AnnLineObject)

            ' Burn this line object in RED

            ' Convert the line points to logical (image coordinates)
            Dim pts() As AnnPoint = {lineObj.StartPoint, lineObj.EndPoint}

            pts = lineObj.ConvertObjectToLogicalPoints(pts)

            ' Convert the points to pixels
            Dim pt1Pixels As PointF = pts(0).ConvertTo(automation.Container.UnitConverter, AnnUnit.Pixel).ToPointF()
            Dim pt2Pixels As PointF = pts(1).ConvertTo(automation.Container.UnitConverter, AnnUnit.Pixel).ToPointF()

            ' Draw it on the image
            g.DrawLine(Pens.Red, pt1Pixels, pt2Pixels)

         ElseIf (TypeOf annObj Is AnnRectangleObject) Then
            Dim rectObj As AnnRectangleObject = DirectCast(annObj, AnnRectangleObject)

            ' Burn this rectangle object in BLUE

            ' Convert the rectangle bounds to logical (image coordinates)
            Dim bounds As AnnRectangle = rectObj.ConvertObjectToLogicalRectangle(rectObj.Bounds)

            ' Convert the bounds to pixels
            Dim boundsPixels As RectangleF = bounds.ConvertTo(automation.Container.UnitConverter, AnnUnit.Pixel).ToRectangleF()

            ' Draw it on the image
            g.DrawRectangle(Pens.Blue, boundsPixels.X, boundsPixels.Y, boundsPixels.Width - 1, boundsPixels.Height - 1)
         End If
      Next
   End Using

   RasterImage.DeleteLeadDC(hdc)

   ' Invalidate
   automation.Viewer.Invalidate()
End Sub
C#Copy Code
private void BurnAllLinesAndRectanglesToImage(AnnAutomation automation) 

   // Create a Graphics object from the RasterImage we are annotating 
   IntPtr hdc = automation.Viewer.Image.CreateLeadDC(); 
   using(Graphics g = Graphics.FromHdc(hdc)) 
   { 
      // Loop through all the objects in the annotation container 
      foreach(AnnObject annObj in automation.Container.Objects) 
      { 
         if(annObj is AnnLineObject) 
         { 
            AnnLineObject lineObj = annObj as AnnLineObject; 
 
            // Burn this line object in RED 
 
            // Convert the line points to logical (image coordinates) 
            AnnPoint[] pts = { lineObj.StartPoint, lineObj.EndPoint }; 
 
            pts = lineObj.ConvertObjectToLogicalPoints(pts); 
 
            // Convert the points to pixels 
            PointF pt1Pixels = pts[0].ConvertTo(automation.Container.UnitConverter, AnnUnit.Pixel).ToPointF(); 
            PointF pt2Pixels = pts[1].ConvertTo(automation.Container.UnitConverter, AnnUnit.Pixel).ToPointF(); 
 
            // Draw it on the image 
            g.DrawLine(Pens.Red, pt1Pixels, pt2Pixels); 
         } 
         else if(annObj is AnnRectangleObject) 
         { 
            AnnRectangleObject rectObj = annObj as AnnRectangleObject; 
 
            // Burn this rectangle object in BLUE 
 
            // Convert the rectangle bounds to logical (image coordinates) 
            AnnRectangle bounds = rectObj.ConvertObjectToLogicalRectangle(rectObj.Bounds); 
 
            // Convert the bounds to pixels 
            RectangleF boundsPixels = bounds.ConvertTo(automation.Container.UnitConverter, AnnUnit.Pixel).ToRectangleF(); 
 
            // Draw it on the image 
            g.DrawRectangle(Pens.Blue, boundsPixels.X, boundsPixels.Y, boundsPixels.Width - 1, boundsPixels.Height - 1); 
         } 
      } 
   } 
 
   RasterImage.DeleteLeadDC(hdc); 
 
   // Invalidate 
   automation.Viewer.Invalidate(); 
}

Remarks

An AnnObject may contain various points, lines, curves and rectangles that denote the object coordinates and where it should be drawn on an image. Also, the AnnObject contains a Matrix object that may be updated with a transformation when the object is moved, rotated or sized. This transformation as well as the container own transformation are used to translate an object point to image coordinates and then to the screen.

The coordinates stored in the object (for example, AnnLineObject.StartPoint or AnnRectangleObject.Bounds are called object coordinates. These coordinates do not translate 1 to 1 to pixel values on the image used in the annotations because of the transformation matrices involved.

The values corresponding to the object coordinates in pixels are called logical coordinates. For example, a logical coordinate of AnnLineObject.StartPoint is its pixel value (in top left-position) in the image its annotating. Converting from object to logical coordinates is what happens when you call the AnnAutomation.Realize method.

To manipulate an object position and size manually from outside the annotation framework, you need to first convert its coordinates to logical values, perform your own transformations, convert them back to object coordinates before setting them back to the object.

To convert a point or a group of points from object to logical coordinates, use the ConvertObjectToLogicalPoints method.

To convert a point or a group of points from logical to object coordinates, use the ConvertLogicalToObjectPoints method.

To convert a rectangle from object to logical coordinates, use the ConvertObjectToLogicalRectangle method.

To convert a rectangle from logical to object coordinates, use the ConvertLogicalToObjectRectangle method.

For an example on converting object to logical and back to object coordinates, refer to ConvertLogicalToObjectPoints.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also

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