赞
踩
首先安装pillow /pywin32 库
通过api读取后台窗口图像,再用pillow对游戏图像进行分析处理判断
- def window_capture(self,hwnd):
- # 获取句柄窗口的大小
- rctA = win32gui.GetWindowRect(hwnd)
- w = rctA[2] - rctA[0]
- h = rctA[3] - rctA[1]
- hwndDC = win32gui.GetWindowDC(hwnd)
- mfcDC = win32ui.CreateDCFromHandle(hwndDC)
- saveDC = mfcDC.CreateCompatibleDC()
- saveBitMap = win32ui.CreateBitmap()
- saveBitMap.CreateCompatibleBitmap(mfcDC, w, h)
- saveDC.SelectObject(saveBitMap)
- saveDC.BitBlt((0, 0), (w, h), mfcDC, (0, 0), win32con.SRCCOPY)
- # saveBitMap.SaveBitmapFile(saveDC, "img_Winapi.bmp")
- ###获取位图信息
- bmpinfo = saveBitMap.GetInfo()
- bmpstr = saveBitMap.GetBitmapBits(True)
- ###生成图像
- im_PIL_TEMP = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']), bmpstr, 'raw', 'BGRX', 0, 1)
- #
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。