python--获得特定程序的屏幕截图并保存为文件
import win32guiimport win32ui
import win32con
name = "test.txt - Notepad"
hwnd = win32gui.FindWindow(None, name)
left, top, right, bot = win32gui.GetWindowRect(hwnd)
w = right - left
h = bot - top
print(w,h)
wDC = win32gui.GetWindowDC(hwnd)
dcObj=win32ui.CreateDCFromHandle(wDC)
cDC=dcObj.CreateCompatibleDC()
dataBitMap = win32ui.CreateBitmap()
dataBitMap.CreateCompatibleBitmap(dcObj, w, h)
cDC.SelectObject(dataBitMap)
cDC.BitBlt((0,0),(w, h) , dcObj, (0,0), win32con.SRCCOPY)
dataBitMap.SaveBitmapFile(cDC, "1.bmp")
# Free Resources
dcObj.DeleteDC()
cDC.DeleteDC()
win32gui.ReleaseDC(hwnd, wDC)
win32gui.DeleteObject(dataBitMap.GetHandle())
主要是利用win32库
以上是 python--获得特定程序的屏幕截图并保存为文件 的全部内容, 来源链接: utcz.com/z/386922.html