python - 设置 ImageGrab 从中获取像素颜色的位置

标签 python python-imaging-library coordinates imagegrab

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

我尝试更改 xyrange 值,但这改变了打印的方式。我是一个初学者,对于这个愚蠢的问题我感到很抱歉,但我已经研究了很长时间并且无法弄清楚。目前它只是从屏幕左上角获取像素。我想捕获 1920x1080 屏幕上的单个中间像素。

谢谢。

最佳答案

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

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

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

<PIL.Image.Image image mode=RGBA size=1x1 at 0x120668748>

关于python - 设置 ImageGrab 从中获取像素颜色的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54352335/

相关文章:

python - 设置标题和轴标签

python - Django 可重用应用程序

python - 保存图像文件Python的快速方法

google-maps - 检查点是否在多边形( map )中

java - 返回区域的查找算法?

python - 使用 Python 查找盘符 (Windows)

python - DPI 缩放级别影响 Python 中的 win32gui GetWindowRect

python - 为什么此功能会为我的所有图像添加边框?

python - 如何从 OSX(雪豹)手动卸载 PIL

arrays - Swift 将坐标追加到数组中并添加到 map