python - 如何捕获窗口照片(缩略图)?

标签 python windows

我想在Windows操作系统中使用Python获取一个窗口的照片(缩略图),我已经有了它的句柄(hwnd)。

最佳答案

来自link i posted in your question comments,我能够得到一个示例,它可以显示我的 python 解释器窗口的缩略图。

from PIL import ImageGrab, Image
import win32gui

hwnd = 2622054 # My python intepreter window
thumbnailsize = 128, 128

# Set the current window to your window
win32gui.SetForegroundWindow(hwnd)
# Get the size of the window rect.
bbox = win32gui.GetWindowRect(hwnd)
# Grab the image using PIL and thumbnail.
img = ImageGrab.grab(bbox)
img.thumbnail(thumbnailsize, Image.ANTIALIAS)
# Save.
img.save('c:/test/test.png')

关于python - 如何捕获窗口照片(缩略图)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13944581/

相关文章:

MySQL 服务无法启动 Windows

windows - 在 PowerShell 中启动一个分离的后台进程

python - 如何使用noise.py模块选择种子

Python 多行正则表达式分隔符

python - 在 Python3 中按索引访问 dict_keys 元素

c++ - GDB Python 支持,ImportError 没有名为 gdb 的模块

sql - 在多个 Windows 版本中测试 .NET 应用程序

mysql - 无法连接到 MySQLCC ERROR 1043 Bad Handshake 上的 MySQL 服务器

windows - 套接字泄漏在netstat和tcpview中未显示的Windows中

python - VS 代码 : "The isort server crashed 5 times in the last 3 minutes..."