ImageGrab.grab(bbox()) 没有 return RGB 值

ImageGrab.grab(bbox()) doesn't return RGB values

这是我的代码:

import pyscreenshot as ImageGrab


class Main:
    px = ImageGrab.grab(bbox=[799, 449, 800, 450]).load()

但是,当我打印 px[0, 0] 时,它 returns 我只是一个 int,而不是 RGB 三元组。有人知道这是为什么吗?

为我执行以下工作

import pyscreenshot as ImageGrab

def main():
    px = ImageGrab.grab(bbox=[799, 449, 800, 450]).load()
    print(px[0, 0]);

main()

在终端

$ python3 test.py                                                                     
(27, 29, 30)

此代码是否适合您(您需要先安装 MSS):

import mss

with mss.mss() as sct:
    img = sct.grab((799, 449, 800, 450))
    print(img.pixel(0, 0))

在我的终端中:

$ python3 test.py                                                                     
(30, 30, 30)