是否可以在特定窗口上使用ImageGrab? (pil)
该代码建议使用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)
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论