我这里有一个简单的代码:
import mss
with mss.mss() as sct:
filename = sct.shot(output="result.png")
result.png
但我想把屏幕上的一部分像这样:
谢谢你帮忙!
发布于 2022-03-13 01:34:51
正如在https://python-mss.readthedocs.io/examples.html上解释的那样,这样的东西应该可以工作:
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}
。您将不得不修改它来捕获屏幕上您想要的部分。
https://stackoverflow.com/questions/71453766
复制相似问题