我想在Windows操作系统中使用python获取一个窗口的照片(缩略图),我已经拥有它的句柄(hwnd)。
答案 0 :(得分:1)
从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')