python3 获取电脑上某个点的颜色RGB值

直接贴代码,比较简单,函数返回的就是rgb的列表

from ctypes import *  # 获取屏幕上某个坐标的颜色

def get_color(x, y):
    gdi32 = windll.gdi32
    user32 = windll.user32
    hdc = user32.GetDC(None)  # 获取颜色值
    pixel = gdi32.GetPixel(hdc, x, y)  # 提取RGB值
    r = pixel & 0x0000ff
    g = (pixel & 0x00ff00) >> 8
    b = pixel >> 16
    return [r, g, b]

 

你可能感兴趣的:(ctypes,python3)