我尝试使用pygetwindow
和ImageGrab
来获取窗口的位置并对其进行快照,但我得到了某种正确的图像,但也从侧面获得了一些额外的像素。从大小中减去一些像素也没有帮助。我做错了什么,或者有更好更简单的方法吗?还尝试使用win32gui
,但得到与图像相同的输出
代码:
import pygetwindow as gw
from time import sleep
from PIL import ImageGrab
win = gw.getWindowsWithTitle('Health Card')[0]
winleft = win.left
wintop = win.top
winright = win.right
winbottom = win.bottom
sleep(3)
print(win.left,win.right,win.bottom,win.top)
a = ImageGrab.grab(bbox=(winleft,wintop,winright,winbottom))
a.save('hey.png')
图片:
我如何才能准确地获取窗口并排除窗口的标题栏
提前感谢:D
问题是由于windows 10中的GUI应用了windows阴影
下面是我如何为
pygetwindow
修复它的:或者,如果您正在使用
win32gui
,请尝试我用
map()
减去两个列表,你可以用任何你喜欢的方法(例如:numpy
)最终输出:
说明: 通常,边框仅用于左、右和底部。我也删除了标题栏,并且我使用了轴差的
+
cuz。这几乎等同于种植。我认为窗口阴影的标准尺寸是7px,所以我们必须去掉像7-10px这样的东西才能保证准确度相关问题 更多 >
编程相关推荐