Conversion of pixel coordinates and logical coordinates

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.