python - 是否有一个公式可以在 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)
将返回:
(75, 75)
推荐阅读
- python - 如何拆分python程序?
- python - Geopandas readfile zip 给出 fiona.errors.DriverError:not Recognized as a supported file format
- swiftui - 日历图像图标
- matlab - 将简单 randles 电路的阻抗拟合到傅里叶变换公式
- amazon-web-services - AWS EC2 用户数据脚本 - 扩展问题
- computer-vision - 没有深度学习的检测到的 2D 边界框的 3D 对象检测
- reactjs - 反应构建路径
- angular - 赛普拉斯没有检测到一些变化
- vb.net - 向数组中添加一个数字,检查该数字是否已经在数组中,并循环检查
- javascript - 如何使外部脚本在 window.onload 上运行