如何将Windows屏幕坐标转换为屏幕截图像​​素坐标

如何将Windows屏幕坐标转换为屏幕截图像​​素坐标

本文介绍了如何将Windows屏幕坐标转换为屏幕截图像​​素坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在屏幕截图上找到一个控件.我有它的屏幕坐标.如何将它们转换为屏幕截图上的坐标?

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

推荐答案

这全部取决于屏幕截图的大小和当前分辨率的大小.

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

假设屏幕截图为800x600,但您当前的屏幕分辨率为1280x720.为了找出800x600图像上的X,Y位置,您需要对1280x720屏幕上X,Y的值进行标准化.

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;

请注意,在800x600图像上,您要查找的对象也较小.所以:

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;

这篇关于如何将Windows屏幕坐标转换为屏幕截图像​​素坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:18