python实现全屏截图(win32)

Python | 2010-04-10 22:14:55 | 阅读 5668 次 | 评论(1)
#!/usr/bin/python
#
-*- coding: UTF-8 -*-

import time
import os, win32gui, win32ui, win32con, win32api

def window_capture():
    hwnd = 0
    hwndDC = win32gui.GetWindowDC(hwnd)
    mfcDC=win32ui.CreateDCFromHandle(hwndDC)
    saveDC=mfcDC.CreateCompatibleDC()
    saveBitMap = win32ui.CreateBitmap()
    MoniterDev=win32api.EnumDisplayMonitors(None,None)
    w = MoniterDev[0][2][2]
    h = MoniterDev[0][2][3]
    print w,h
    saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
    saveDC.SelectObject(saveBitMap)
    saveDC.BitBlt((0,0),(w, h) , mfcDC, (0,0), win32con.SRCCOPY)
    bmpname=win32api.GetTempFileName(".","")[0]+'.bmp'
    saveBitMap.SaveBitmapFile(saveDC, bmpname)
    return bmpname

os.system(window_capture())
文章评论,共1条
Image
1楼: 敌夏吹既 发表于 2019-09-10 12:38   回复
游客请输入验证码
浏览1924921次
文章归档
最新评论
  • Miss_Zou:不都是复制粘贴的吗
  • Miss_Zou:目测是大佬
  • 神犇dengyuhy:语文很好