首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何使用mss python从屏幕的一部分截图?

如何使用mss python从屏幕的一部分截图?
EN

Stack Overflow用户
提问于 2022-03-13 01:28:18
回答 1查看 2K关注 0票数 6

我这里有一个简单的代码:

代码语言:javascript
代码运行次数:0
运行
复制
import mss
with mss.mss() as sct:
    filename = sct.shot(output="result.png")

result.png

但我想把屏幕上的一部分像这样:

谢谢你帮忙!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-13 01:34:51

正如在https://python-mss.readthedocs.io/examples.html上解释的那样,这样的东西应该可以工作:

代码语言:javascript
代码运行次数:0
运行
复制
with mss.mss() as sct:
    # The screen part to capture
    monitor = {"top": 160, "left": 160, "width": 160, "height": 135}
    output = "sct-{top}x{left}_{width}x{height}.png".format(**monitor)

    # Grab the data
    sct_img = sct.grab(monitor)

    # Save to the picture file
    mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
    print(output)

这只是网站上的一个例子。您可以通过修改monitor字典来调整正在拍摄屏幕快照的屏幕部分。例如,您可以将它从{"top": 160, "left": 160, "width": 160, "height": 135}更改为{"top": 10, "left": 14, "width": 13, "height": 105}。您将不得不修改它来捕获屏幕上您想要的部分。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71453766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档