gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 10:26:51 26 4
gpt4 key购买 nike

我想在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com