如何使用lackey在Python中捕获屏幕截图?
我想做一个屏幕截图与仆人理想的屏幕上的应用程序,但首先,一个屏幕截图的整个屏幕将是好的 我试过了如何使用lackey在Python中捕获屏幕截图?,python,lackey,Python,Lackey,我想做一个屏幕截图与仆人理想的屏幕上的应用程序,但首先,一个屏幕截图的整个屏幕将是好的 我试过了 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) 无法打开图片,因为函数captu
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()
美好的后续问题:您的示例正在对我从MSYS而不是notepad.exe运行的批处理区域进行屏幕截图。应该更改什么以获得校正区域的屏幕截图?非常感谢@让·弗朗索斯特。我也注意到了,但我找不到原因。“我想这与你如何获得应用程序窗口的区域有关。”Jean FrancoisT。我在Lackey的应用程序、Screen和Region类中使用了不同的方法,但无论我尝试了什么,我似乎都无法只获得记事本窗口,而不获得运行代码与代码的窗口。奇怪。。。你认为这是一只虫子吗?对于切换的需要,pywin32可能可以帮助切换到窗口并获得适当的窗口区域。无论如何,实际上我可能不需要这个功能。而是为了测试不同的功能。