是否可以在特定窗口上使用ImageGrab? (pil)

发布于 2025-02-10 07:46:52 字数 730 浏览 1 评论 0原文

该代码建议使用ImageGrab(pil)进行特定窗口的屏幕截图,但是屏幕截图不是Acurrate,我不知道为什么。

这是代码所采用的屏幕截图(两者都不合适,也不是正确的位置)

这是代码

import pygetwindow as gw
import PIL.ImageGrab
from pynput.mouse import Button, Controller
mouse = Controller()
from pynput.keyboard import Key, Controller
keyboard = Controller()
chosenWindow = gw.getWindowsWithTitle('Discord')[0]
print(chosenWindow.topleft)
print(chosenWindow.bottomright)
Im = PIL.ImageGrab.grab(bbox=(chosenWindow.topleft[0],chosenWindow.topleft[1],chosenWindow.bottomright[0],chosenWindow.bottomright[1]))
Im.show()

This code is suppused to take a screenshot of a specific window using ImageGrab(PIL), however the screenshot is not acurrate and I have no Idea why.

here is a screenshot the code took(both not the right size and not in the right position)
The screenshot

and this is the code

import pygetwindow as gw
import PIL.ImageGrab
from pynput.mouse import Button, Controller
mouse = Controller()
from pynput.keyboard import Key, Controller
keyboard = Controller()
chosenWindow = gw.getWindowsWithTitle('Discord')[0]
print(chosenWindow.topleft)
print(chosenWindow.bottomright)
Im = PIL.ImageGrab.grab(bbox=(chosenWindow.topleft[0],chosenWindow.topleft[1],chosenWindow.bottomright[0],chosenWindow.bottomright[1]))
Im.show()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文