Realize screen

import time
import win32gui, win32ui, win32con, win32api


window_capture DEF (filename):
HWND ID = Window # 0, No. 0 indicates that the current active window
# acquisition window device context DC (Divice Context) The window handle
hwndDC = win32gui.GetWindowDC (HWND)
# The acquisition window mfcDC the DC
mfcDC win32ui.CreateDCFromHandle = (hwndDC)
# mfcDC create compatible DC
SaveDC = mfcDC.CreateCompatibleDC ()
# create bigmap ready to save the picture
saveBitMap = win32ui.CreateBitmap ()
# get monitor information
MoniterDev = win32api.EnumDisplayMonitors (None, None)
w MoniterDev = [0] [2] [2]
H = MoniterDev [0] [2] [. 3]
# Print W, image size H #
# of open space bitmap
saveBitMap.CreateCompatibleBitmap (mfcDC, W, H)
# height saveDC, the screenshot is saved to saveBitmap in
saveDC.SelectObject (saveBitMap)
# intercepts from the upper left corner (0,0) the length and width (w, h) of the picture
saveDC.BitBlt((0, 0), (w, h), mfcDC, (0, 0), win32con.SRCCOPY)
saveBitMap.SaveBitmapFile(saveDC, filename)


beg = time.time()
for i in range(10):
window_capture("haha.jpg")
end = time.time(https://www.qqtn.com/wm/nanshengwm_3.html)
print(end - beg)

Guess you like

Origin www.cnblogs.com/liyanyan665/p/11278094.html