设置ImageGrab从哪里获取像素颜色

问题描述 投票:1回答:1

我正在使用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()

我尝试更改rangexy值,但这改变了打印出来的方式。我是一个初学者,我为这个愚蠢的问题感到抱歉,但我已经这么久了,无法弄清楚。目前它只是从我的屏幕左上角获取像素。我想拍摄1920x1080屏幕上的单个中间像素。

谢谢。

python coordinates python-imaging-library
1个回答
1
投票

未经测试,但是像这样你指定bounding box只是1x1像素:

pixel=ImageGrab.grab((960,540,961,541)) 

如果你检查它会给你这个:

<PIL.Image.Image image mode=RGBA size=1x1 at 0x120668748>
© www.soinside.com 2019 - 2024. All rights reserved.