Python 屏幕坐标点取色


import ctypes
from ctypes import wintypes

class Screen:
    user32 = ctypes.WinDLL('user32', use_last_error=True)
    gdi32 = ctypes.WinDLL('gdi32', use_last_error=True)

    # 注册user32中的GetDC参数和返回值
    user32.GetDC.restype = wintypes.HDC
    user32.GetDC.argtypes = (wintypes.HWND,)
    # 注册GetPixel中的GetPixel参数和返回值
    gdi32.GetPixel.restype = wintypes.COLORREF
    gdi32.GetPixel.argtypes = (wintypes.HDC, ctypes.c_int, ctypes.c_int)

    @staticmethod
    def getColor(x, y):
        hdc = Screen.user32.GetDC(None)
        color = Screen.gdi32.GetPixel(hdc, x, y)
        r = color & 0xFF
        g = color >> 8 & 0xFF
        b = color >> 16 & 0xFF
        return (r, g, b)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM