pyautogui 在知道 2 个角的特定区域创建屏幕截图

pyautogui creating screenshot in specific area knowing 2 corners

我有 2 个角的坐标 https://prnt.sc/w2jryh(正方形的 d 和 b 点的 x 和 y 坐标)。我需要在这个正方形的区域内创建屏幕截图,但是当我尝试这样做时,它失败了,要么屏幕截图太多,要么太少。这可能是什么神奇的公式:)这是我试过的:

pyautogui.screenshot("testScr.png",region=(blackRookCornerX,whiteRookCornerY,whiteRookCornerX,blackRookCornerY))

基本上是获取坐标并尝试获取正确的屏幕截图。这里的坐标是正确的。

来自他们的docs

There is also an optional region keyword argument, if you do not want a screenshot of the entire screen. You can pass a four-integer tuple of the left, top, width, and height of the region to capture:

前两个数字应该是您要拍摄的左上角的 x,y 坐标,第三个数字是 right/left 要走多远(以像素为单位),第四个up/down 是多远(以像素为单位)。

试试这个:

pyautogui.screenshot("testScr.png", region=(blackRookCornerX, whiteRookCornerY, 100, 100))

从 100 等宽泛的数字开始,然后慢慢减少,直到获得完美的屏幕截图。

你可以为每个角制作一个热键来收集坐标;只需将鼠标放在这些角落并按下每个热键即可。然后,一旦你对两个角都做了这个并且有两个变量,就将这些变量用于你的屏幕截图。