【问题标题】:how to convert windows screen coordinates to screenshot pixel coordinates?如何将 Windows 屏幕坐标转换为屏幕截图像​​素坐标?
【发布时间】:2011-07-20 02:35:05
【问题描述】:

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

【问题讨论】:

    标签: windows winapi gdi


    【解决方案1】:

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      相关资源
      最近更新 更多