![](/img/trans.png)
[英]How to get actual Pixel Color value from PIL.ImageGrab.grab() in Python?
[英]Set Where ImageGrab Gets Pixel Color From
我正在使用 PIL 的 ImageGrab 來獲取屏幕上特定像素的 RGB 值。 我無法理解在哪里設置 x 和 y 坐標以獲取像素。 這是到目前為止的模式代碼:
from PIL import ImageGrab
import threading
def getcol():
global pxcolor
threading.Timer(0.5, getcol).start()
pixel=ImageGrab.grab().load()
for y in range(0,1,1):
for x in range(0,1,1):
pxcolor=pixel[x,y]
print(pxcolor)
getcol()
我嘗試更改x
和y
的range
值,但這改變了它的打印方式。 我是一個初學者,我很抱歉這個愚蠢的問題,但我已經研究了很長時間並且無法弄清楚。 目前它只是從我的屏幕左上角獲取像素。 我想在我的 1920x1080 屏幕上捕獲單個中間像素。
謝謝。
未經測試,但類似這樣的事情,你指定一個只有 1x1 像素的邊界框:
pixel=ImageGrab.grab((960,540,961,541))
如果您檢查它,它將為您提供:
<PIL.Image.Image image mode=RGBA size=1x1 at 0x120668748>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.