这是我的代码:
import pyscreenshot as ImageGrab
class Main:
px = ImageGrab.grab(bbox=[799, 449, 800, 450]).load()
但是,当我打印 px[0, 0] 时,它只返回一个 int,而不是 RGB 三元组。有人知道这是为什么吗?
这段代码对你有用吗(你需要先安装 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)
为我执行以下工作
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)