今天使用Python截屏,这次分享三种方法,大家根据自己的实际情况,使用不同的方法。使用之前,必须现在各自对应的第三方库。
import pyautogui
class gng() :
myScreenshot = pyautogui.screenshot()
myScreenshot.save('./save.png')
gng()
import mss
import mss.tools
with mss.mss() as sct:
monitor = {"top": 160, "left": 160, "width": 160, "height": 135}
output = "sct-{top}x{left}_{width}x{height}.png".format(**monitor)
sct_img = sct.grab(monitor)
mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
print(output)
import pyscreenshot as ImageGrab
# 全屏截取
im=ImageGrab.grab()
im.show()
# 截取部分
im=ImageGrab.grab(bbox=(10,10,500,500))
im.show()
# 保存文件
ImageGrab.grab_to_file('im.png')
希望,今天的分享,对你有启发。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有