使用ctypes模块实现提取当前屏幕某一坐标RGB
from ctypes import * # 获取屏幕上某个坐标的颜色 import time def getRgb(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 rgb = [r, g, b] return rgb start = time.time() print(getRgb(x=2, y=3)) # 写xy坐标,他将提取这一像素点的RGB,以列表形式返回 end = time.time() t = end - start # 计算调用一次的时间 print(t)
-End-