The conversion of pixel coordinates and logical coordinates requires two elements: the position of the window sitting and the size of the window
Pixel coordinates (1024*768) X: 0--1024 Y: 0--768
Logical coordinates (0--1)
Public Point pixeltological (point pixel)
{
// Viewportorigin: display the upper left corner of the image
Point offset = Viewportorigin;
Double Scale = viewportwidth/actualwidth;
Point logical = New Point (pixel. x * Scale) + Offset. X, (pixel. Y * Scale) + Offset. y );
Return Logical;
}
On this basis, you can also convert logical coordinates and custom coordinates. The core idea is the same: to know the coordinates of the sitting cursor and the coordinates in the lower right corner, in this way, we can calculate the ratio of the coordinates directly. This is a simple solution I have come up with, but there will be deformation when processing the projection coordinates. I don't know if there are other simple solutions, yes.