我正在尝试使用BitBlt()
函数来复制位图数据。
当我使用python win32ui/win32gui
API
时,平均花费的时间约为30毫秒,而当我使用C ++调用时,API
的平均时间约为10- 15毫秒
所以我想知道,这种行为可能是什么原因?
由于
编辑:这是片段:
python:
hdesktop = win32gui.GetDesktopWindow()
# create a device context
desktop_dc = win32gui.GetWindowDC(hdesktop)
img_dc = win32ui.CreateDCFromHandle(desktop_dc)
# create a memory based device context
mem_dc = img_dc.CreateCompatibleDC()
# create a bitmap object
screenshot = win32ui.CreateBitmap()
screenshot.CreateCompatibleBitmap(img_dc, width, height)
oldbmp = mem_dc.SelectObject(screenshot)
# copy the screen into our memory device context
mem_dc.BitBlt((destUpLeftX, destUpLeftY), (width, height), img_dc, (srcUpLeftX, srcUpLeftY),win32con.SRCCOPY)
mem_dc.SelectObject(oldbmp)
win32gui.DeleteObject(screenshot.GetHandle())
img_dc.DeleteDC()
win32gui.ReleaseDC(hdesktop, desktop_dc)
mem_dc.DeleteDC()
C ++:
HDC hwindowDC=GetDC(GetDesktopWindow());
HDC hwindowCompatibleDC=CreateCompatibleDC(hwindowDC);
// create a bitmap
HBITMAP hbwindow = CreateCompatibleBitmap( hwindowDC, width, height);
LOG(LOG_DBG, "before SelectObject");
// SAVE OLD BITMAP
HGDIOBJ hOldBmp = SelectObject(hwindowCompatibleDC, hbwindow); //copy from hwindowCompatibleDC to hbwindow
BitBlt(hwindowCompatibleDC, destUpLeftX, destUpLeftY, width, height, hwindowDC, srcUpLeftX, srcUpLeftY, SRCCOPY);
SelectObject(hwindowCompatibleDC, hOldBmp);
DeleteDC(hwindowCompatibleDC);
DeleteObject(hbwindow);
// RELEASE WINDOW DC
ReleaseDC(GetDesktopWindow(), hwindowDC);