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