在 Python 中是否有为分辨率创建通用坐标的公式?

Is there a formula to create universal coordinates for resolutions in Python?

在autoit中,代码如下:

Func _ConvertXY(ByRef $Xin, ByRef $Yin)
    $Xin = Round(($Xin / 2560) * @DesktopWidth)
    $Yin = Round(($Yin / 1440) * @DesktopHeight)
EndFunc   ;==>_ConvertXY

$flashXa = 1059
$flashYa = 1285 ; Your intended coordinates on the original 2560x1440 desktop
_ConvertXY($flashXa, $flashYa) ; Convert proportionally to the actual desktop size

我正在尝试做同样的事情,但在 Python - 所以基本上它会将坐标调整为相对于 1440p 屏幕的屏幕尺寸,而不管你的分辨率如何。

这是我收集到的您正在寻找的内容:

def res_conv(x: int, y: int, resolution_from: tuple, resolution_to: tuple) -> tuple:
    assert x < resolution_from[0] and y < resolution_from[1], "Input coordinate is larger than resolution"
    x_ratio = resolution_to[0] / resolution_from[0] # ratio to multiply x co-ord
    y_ratio = resolution_to[1] / resolution_from[1] # ratio to multiply y co-ord
    return int(x * x_ratio), int(y * y_ratio)

示例:

res_conv(100, 100, (2560, 1440), (1920, 1080)

会 return:

(75, 75)