图像抓取。抓取(bbox)获取的大小不正确。我是否正确使用bbox?

2024-04-25 11:48:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用ImageGrab来抓取屏幕的某一部分,但它并没有抓取bbox设置的整个区域。你知道吗

为了确保正确使用bbox,我尝试使用ImageGrab方法中的bbox参数简单地捕获整个屏幕。你知道吗

我使用PyAutoGUI和Tkinter来验证我的显示器的大小(都显示我的屏幕宽度为1680,屏幕高度为1050),然后在bbox参数中使用这些尺寸。但是,当我这样做时,它只捕获屏幕的一小部分,如下所示:

enter image description here

当我使用图像.grab()在没有参数的情况下,它捕获整个屏幕,没有任何问题:

enter image description here

这是我的密码:

import pyautogui
from PIL import ImageGrab, Image, ImageOps
import Tkinter as Tk

root = Tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

print(screen_width)
print(screen_height)

print(pyautogui.size())

ImageGrab.grab().show()
ImageGrab.grab(bbox=(0, 0, screen_width, screen_height)).show()

如果我没有正确使用bbox参数,您能解释一下如何使用它吗?你知道吗


Tags: import参数屏幕tkinterrootwidthscreentk