簡體   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