ImageGrab.grab(bbox())不返回RGB值

时间:2019-11-30 15:06:29

标签: python screenshot screen-capture

这是我的代码:

import pyscreenshot as ImageGrab


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

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

2 个答案:

答案 0 :(得分:1)

此代码对您有用吗(您需要先安装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)

答案 1 :(得分:0)

为我执行以下工作

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)