在 python 中截取一个应用程序,不管它前面是什么 [英] screenshot an application in python, regardless of what's in front of it
问题描述
所以我可以使用PIL来抓取桌面的截图,然后使用pywin32来获取它的矩形并裁剪出我想要的部分.但是,如果窗口前面有我想要的东西,它会遮挡我想要截图的应用程序.有什么方法可以让窗口说应用程序当前正在显示什么?它在某处拥有这些数据,即使它前面有其他窗口也是如此.
我在这里的答案中发布了工作代码:非活动窗口的 Python 屏幕截图.它使用 PrintWindow
函数.这是复制隐藏窗口图像的正确"方法,但这并不意味着它总是有效.这取决于实现正确消息的程序,WM_Print
响应.
如果您尝试使用 PrintWindow
它不起作用,那么您唯一剩下的选择就是在使用 BitBlit
之前将窗口放在前面.>
So I can use PIL to grab a screenshot of the desktop, and then use pywin32 to get its rectangle and crop out the part I want. However, if there's something in front of the window I want, it'll occlude the application I wanted a screenshot of. Is there any way to get what windows would say an application is currently displaying? It has that data somewhere, even when other windows are in front of it.
I posted working code in the answer here: Python Screenshot of inactive window. It uses the PrintWindow
function.
This is the "correct" way to copy the image of a hidden window, but that doesn't mean that it will always work. It depends on the program implementing the proper message, WM_Print
response.
If you try to use PrintWindow
it doesn't work, then your only remaining option would be to bring the window to the front before taking a BitBlit
.
这篇关于在 python 中截取一个应用程序,不管它前面是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!