Pyautogui 截图。它去哪里?如何保存并稍后查找?

问题描述 投票:0回答:2

我正在从 Al Sweigart 的 YouTube 视频中学习如何将无聊的事情自动化。我开始截图了。他在视频中没有真正解释,所以我测试了一下。我发现它会截取整个桌面的屏幕截图,但我不知道它们去了哪里。我只能在进行整个计算机搜索时才能找到它,并且我不知道如何将其放入那里的文件夹中。

基本上我问的是如何存储图像并找到由

pyautogui.screenshot()
函数拍摄的图像。我目前不打算将其用于任何用途,我只是想知道如何做到这一点。我去了 pyautogui 网站,但没有找到任何关于在哪里找到以及如何保存屏幕截图的信息。预先感谢您的宝贵时间!

python windows python-3.x automation pyautogui
2个回答
8
投票

这是有关在 pyautogui 中保存屏幕截图的文档的链接:

https://github.com/asweigart/pyautogui#user-content-screenshot-functions

截图函数返回一个PIL.Image。您可以使用它的 save 方法将其保存到文件中。

import pyautogui
im1 = pyautogui.screenshot()
im1.save(r"c:\path\to\my\screenshot.png")

您还可以在截图方法调用中传递您想要保存文件的路径:

import pyautogui
pyautogui.screenshot(r"c:\path\to\my\screenshot1.png")

4
投票

您遵循了 pyautogui 文档 吗?

它明确表示: PyAutoGUI 可以截取屏幕截图,将其保存到文件中,并在屏幕中定位图像

调用screenshot()将返回一个Image对象。可以用不同的方式调用它:

>>> im1 = pyautogui.screenshot()  # return an image object
>>> im2 = pyautogui.screenshot('my_screenshot.png')  # image name will be as per parameter
>>> im3 = pyautogui.screenshot(region=(0,0, 300, 400)) # mention spedific region to get the screenshot 

它们都返回一个图像对象,以后可以根据要求使用/保存:

>>> im1.size()  # will return a dimension of image as a tuple  
>>> im2.save("<imagepath where you wish to save your image >") # save the image
>>> im.getpixel((100, 200)) # return color value of the point mentioned 
© www.soinside.com 2019 - 2024. All rights reserved.