简体   繁体   English

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

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

This is my code:这是我的代码:

import pyscreenshot as ImageGrab


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

However, when I print px[0, 0] it returns me just an int, not an RGB triplet.但是,当我打印 px[0, 0] 时,它只返回一个 int,而不是一个 RGB 三元组。 Anyone knows why that is?有谁知道这是为什么?

Does this code work for you (you will need to install MSS first):此代码是否适合您(您需要先安装MSS ):

import mss

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

In my terminal:在我的终端中:

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

executing the following works for me为我执行以下工作

import pyscreenshot as ImageGrab

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

main()

in the terminal在终端

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM