繁体   English   中英

如何读取活动窗口给定像素的 RGB 值?

[英]How can I read the RGB value of a given pixel of an active window?

如果我在屏幕上有一个坐标,是否可以在不先截图的情况下检索它的 RGB 值?

我正在处理这个:

import time
from ctypes import *

GetForegroundWindow = windll.user32.GetForegroundWindow
GetWindowDC = windll.user32.GetWindowDC
GetPixel = windll.gdi32.GetPixel
ReleaseDC = windll.user32.ReleaseDC
foreground_window = GetForegroundWindow()
dc = GetWindowDC(foreground_window)
rgb = GetPixel(dc, 10, 0)
ReleaseDC(foreground_window, dc)

r = rgb & 0xff
g = (rgb >> 8) & 0xff
b = (rgb >> 16) & 0xff
print "RGB(%d, %d, %d)" % (r, g, b)

我在这里找到了,我喜欢它涉及ctypes

我有这个问题:

如何将setcursorposition到我从中采样颜色的同一个位置? 有了这个?

ctypes.windll.user32.SetCursorPos(100, 100)

似乎您缺少导入。 在 Windows 中,您可以这样做:

import win32api
win32api.SetCursorPos((x,y))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM