how to convert windows screen coordinates to screenshot pixel coordinates?

瘦欲@ 提交于 2019-12-08 12:35:50

问题


I need to find a control on screenshot. I have its screen coordinates. How can I convert them to coordinates on screenshot?


回答1:


It all depends on the size of the screenshot and the size of your current resolution.

Let's say the screenshot is 800x600, but your current screen resolution is 1280x720. In order to find out the X,Y position on a 800x600 image, you need to normalize the values you have of X,Y on a 1280x720 screen.

normalized_x = (x * 800) / 1280;
normalized_y = (y * 600) / 720;

Note that the object you are looking for is also smaller on a 800x600 image. So:

// w and h represents the size of the object at 1280x720
normalized_w = (w * 800) / 1280; 
normalized_w = (h * 600) / 720;


来源:https://stackoverflow.com/questions/5385274/how-to-convert-windows-screen-coordinates-to-screenshot-pixel-coordinates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!