[英]How to capture screenshot in Python with lackey?
我想这样做的截图与应用程序的理想屏幕的走狗 (但是,整个屏幕的截图,开始将OK)。
我努力了
from lackey import *
notepad = App('notepad.exe')
notepad.open()
focusWindow = notepad.focusedWindow()
s = Screen(0)
r = s.capture()
with open("toto.bmp", "wb") as f:
f.write(r)
图片无法打开,因为函数capture
返回numpy.ndarray
。
我也尝试执行以下操作,但结果相同:
r = Screen.capture(focusWindow)
有人知道如何制作屏幕截图吗?
谢谢
您可以使用PIL库中的Image.fromarray和Image.save方法来保存图像。 由于某些原因,下面的代码捕获了运行脚本以及记事本应用程序的窗口,我想您可能需要对其进行调整。
from lackey import *
from PIL import Image
notepad = App('notepad.exe')
notepad.open()
focusWindow = notepad.focusedWindow()
sleep(5) # allow some time for the notepad window to appear before capture.
screen = Screen()
capture = screen.capture(focusWindow)
image = Image.fromarray(capture)
image.save("test.bmp")
notepad.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.