Converts an array of points from logical to object coordinates.
public [Leadtools.Annotations.AnnPoint[]](annpoint.html) ConvertLogicalToObjectPoints(
Leadtools.Annotations.AnnPoint[] points
)
Public Function ConvertLogicalToObjectPoints( _
ByVal points() As Leadtools.Annotations.AnnPoint _
) As Leadtools.Annotations.AnnPoint()
public:
Leadtools.Annotations.array<AnnPoint>^ ConvertLogicalToObjectPoints(
Leadtools.Annotations.array<AnnPoint>^ points
)
points
An array points in logical coordinates.
An array of points representing the original array but in object coordinates.
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 System.Drawing.Drawing2D.Matrix object that may be updated with a transformation when the object is moved, rotated or sized. This transformation as well as the container's 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 it is annotating. Converting from object to logical coordinates is what happens when you call the AnnAutomation.Realize method.
To manipulate an object's 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 coordinates, refer to ConvertObjectToLogicalPoints.
This example will offset all the line and rectangle objects to the left by 5 pixels
using Leadtools;
using Leadtools.Annotations;
using Leadtools.Codecs;
using Leadtools.WinForms;
using Leadtools.Drawing;
private void OffsetLinesAndRectangles(AnnAutomation automation)
{
// 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;
// Move this line object to the left by 5 logical pixels
// 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();
// Move them to the right
pt1Pixels.X -= 5;
pt2Pixels.Y -= 5;
// Set it back to the line
pts[0] = new AnnPoint(pt1Pixels, AnnUnit.Pixel);
pts[1] = new AnnPoint(pt2Pixels, AnnUnit.Pixel);
pts = lineObj.ConvertLogicalToObjectPoints(pts);
lineObj.StartPoint = pts[0];
lineObj.EndPoint = pts[1];
}
else if (annObj is AnnRectangleObject)
{
AnnRectangleObject rectObj = annObj as AnnRectangleObject;
// Yes, get the bounds in pixels
// 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();
// Move it to the right
boundsPixels.Offset(-5, 0);
// Re-set to bounds
bounds = rectObj.ConvertLogicalToObjectRectangle(new AnnRectangle(boundsPixels, AnnUnit.Pixel));
rectObj.Bounds = bounds;
}
}
// Invalidate
automation.Viewer.Invalidate();
}
Imports Leadtools
Imports Leadtools.Annotations
Imports Leadtools.Codecs
Imports Leadtools.WinForms
Imports Leadtools.Drawing
Private Sub OffsetLinesAndRectangles(ByVal automation As AnnAutomation)
' 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)
' Move this line object to the left by 5 logical pixels
' 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()
' Move them to the right
pt1Pixels.X -= 5
pt2Pixels.Y -= 5
' Set it back to the line
pts(0) = New AnnPoint(pt1Pixels, AnnUnit.Pixel)
pts(1) = New AnnPoint(pt2Pixels, AnnUnit.Pixel)
pts = lineObj.ConvertLogicalToObjectPoints(pts)
lineObj.StartPoint = pts(0)
lineObj.EndPoint = pts(1)
ElseIf (TypeOf annObj Is AnnRectangleObject) Then
Dim rectObj As AnnRectangleObject = DirectCast(annObj, AnnRectangleObject)
' Yes, get the bounds in pixels
' 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()
' Move it to the right
boundsPixels.Offset(-5, 0)
' Re-set to bounds
bounds = rectObj.ConvertLogicalToObjectRectangle(New AnnRectangle(boundsPixels, AnnUnit.Pixel))
rectObj.Bounds = bounds
End If
Next
' Invalidate
automation.Viewer.Invalidate()
End Sub
Products |
Support |
Feedback: ConvertLogicalToObjectPoints Method - Leadtools.Annotations |
Introduction |
Help Version 19.0.2017.6.20
|
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.