我是新手。我试着用mss截图监视器。我的代码:
for i in range(1, 20000):
cactus_box = {'left': 508, 'top': 382, 'width': 30, 'height': 33}
sct = mss()
sct_img = sct.grab(cactus_box)当我运行代码时,显示以下错误:
File "C:\Users\xxxx\AppData\Local\Programs\Python\Python36-32\lib\site-packages\mss\windows.py", line 203, in grab
raise ScreenShotError('gdi32.GetDIBits() failed.', locals())
mss.exception.ScreenShotError: ('gdi32.GetDIBits() failed.', {'bits': 0, 'height': 33, 'width': 30, 'gdi': <WinDLL 'gdi32', handle 75f00000 at 0x93dd5f0>, 'monitor': {'left': 508, 'top': 382, 'width': 30, 'height': 33}, 'self': <mss.windows.MSS object at 0x093DD810>})请,有人可以教我解决这个错误
发布于 2018-05-25 00:41:06
编辑:这是由于资源没有被释放。在MSS 4.0.0或更高版本中已修复此问题。
你能试着在for循环之外使用MSS吗?类似于:
with mss() as sct:
cactus_box = {'left': 508, 'top': 382, 'width': 30, 'height': 33}
for i in range(1, 20000):
sct_img = sct.grab(cactus_box)错误消息不是很明确,但它告诉您截图是不可能的(没有检索到位)。但是我们不能知道原因。可能是内存错误。
此外,尝试打印i以查看它是否及早出现错误。
https://stackoverflow.com/questions/50511457
复制相似问题