首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PyScreeze崩溃: OSError: winll.gdi32.GetPixel失败:返回-1

PyScreeze崩溃: OSError: winll.gdi32.GetPixel失败:返回-1
EN

Stack Overflow用户
提问于 2022-04-02 09:26:57
回答 1查看 181关注 0票数 0

试图检查像素的颜色:

代码语言:javascript
运行
复制
while True:
    x, y = 1742, 979
    r,g,b = pyautogui.pixel(x, y)
    if b == 106:
        #some more code

完整的回溯:

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 119, in __win32_openDC
    yield hDC
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 610, in pixel
    raise WindowsError("windll.gdi32.GetPixel failed : return {}".format(color))
OSError: windll.gdi32.GetPixel failed : return -1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\OneDrive\Combined_180222_desktop_version .py", line 500, in <module>
    detection()
  File "c:\Users\OneDrive\Combined_180222_desktop_version .py", line 468, in detection
    r,g,b = py.pixel(x, y)
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 614, in pixel
    return (r, g, b)
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pyscreeze\__init__.py", line 123, in __win32_openDC
    raise WindowsError("windll.user32.ReleaseDC failed : return 0")
OSError: windll.user32.ReleaseDC failed : return 0

公认的答案here说:“这是PyScreeze 0.1.28中已经解决的问题,所以您只需要通过运行pip install -U pyscreeze来更新它。”

我上的是PyScreeze 0.1.28,所以不是这样的。公认的答案here谈到手动释放所有DC,但当我直接使用.pixel函数而不是win32时,我不知道如何做到这一点。

EN

回答 1

Stack Overflow用户

发布于 2022-04-02 13:10:38

解决方法,直到管理包的人回复。不修复错误,只需使用tryexcept处理它。

代码语言:javascript
运行
复制
   while True:
        try:
            x, y = 1742, 979
            r,g,b = pyautogui.pixel(x, y)
            if b == 106:
                #some more code
        except:
            x, y = 1742, 979
            r,g,b = pyautogui.pixel(x, y)
            if b == 106:
                #some more code
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71716340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档