Home : Windows Forms Viewing Controls : Find the absolute coordinates of an image
Q10110 - HOWTO: Find the absolute coordinates of an image

When using a Viewport (WorkspaceViewer, AnnotateViewer, etc.) there may be some times that coordinates are needed that are absolute to the image, and not to the currently visible part of the image.  This may be an issue, for example, when creating annotations on an image that is zoomed or scrolled.  The code below shows how to find the exact X and Y pixel coordinates.

[C#]

int viewportX = e.X - this.Viewer.ScrollPosition.X;
int viewportY = e.Y - this.Viewer.ScrollPosition.Y;
double imageXPosition = viewportX / this.Viewer.Zoom;
double imageYPosition = viewportY / this.Viewer.Zoom;

 [VisualBasic]

Dim viewportX As Integer = e.X - Me.Viewer.ScrollPosition.X
Dim viewportY As Integer = e.Y - Me.Viewer.ScrollPosition.Y
Dim imageXPosition As Integer = viewportX / Me.Viewer.Zoom
Dim imageYPosition As Integer = viewportY / Me.Viewer.Zoom
Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved