好的,我在使用此功能时遇到此错误(错误:CreateCompatibleDC失败):
import win32api, win32ui, win32gui, win32con
def grab():
global hwin, width, height, left, top
hwindc = win32gui.GetWindowDC(hwin)
srcdc = win32ui.CreateDCFromHandle(hwindc)
memdc = srcdc.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(srcdc, width, height)
memdc.SelectObject(bmp)
memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
#bmp.SaveBitmapFile(memdc, 'screenshot.bmp')
return BMP(bmp, memdc)
hwin = win32gui.GetDesktopWindow()
width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)
它说:
Traceback (most recent call last):
File "<pyshell#98>", line 1, in <module>
grab()
File "<pyshell#43>", line 9, in grab
bmp.CreateCompatibleBitmap(srcdc, width, height)
error: CreateCompatibleDC failed
我认为这是因为我有太多的DC,但是当我删除DC时,它并没有修复任何东西。请帮忙!谢谢!