zoukankan      html  css  js  c++  java
  • Python 屏幕坐标点取色

    import ctypes
    from ctypes import wintypes
    import pyautogui
    
    user32 = ctypes.WinDLL('user32', use_last_error=True)
    # 注册user32中的GetDC参数和返回值
    user32.GetDC.restype = wintypes.HDC
    user32.GetDC.argtypes = (wintypes.HWND,)
    
    gdi32 = ctypes.WinDLL('gdi32', use_last_error=True)
    # 注册GetPixel中的GetPixel参数和返回值
    gdi32.GetPixel.restype = wintypes.COLORREF
    gdi32.GetPixel.argtypes = (wintypes.HDC, ctypes.c_int, ctypes.c_int)
    
    def getScreenColor(self):
        # 获取当前鼠标坐标
        x, y = pyautogui.position()
        hdc = user32.GetDC(None)
        color = gdi32.GetPixel(hdc, x, y)
        r = color & 0xFF
        g = color >> 8 & 0xFF
        b = color >> 16 & 0xFF
        return (r, g, b)
    
  • 相关阅读:
    代码查错1
    代码查错
    垃圾回收器
    面试题(操作语句)
    面试题(JVM加载机制)
    面试题(线程)
    异常
    IO流
    es5 学习笔记
    ECMAScript5 Object的新属性方法
  • 原文地址:https://www.cnblogs.com/congxinglong/p/15410061.html
Copyright © 2011-2022 走看看