我有以下代碼正常工作,它將我的應用程序上的活動窗口的快照放入HBITMAP變量並將其保存在文件中。 現在我想根據給定的開始座標和寬度/高度裁剪圖像並僅保存圖像的一部分。獲取窗口快照並剪裁它
重要的一點是,我要保存窗口與標題欄,不只是客戶區域,所以很容易實現與PrintWindow()而不是BitBlt的()方法。
我更喜歡使用PrintWindow()的解決方案,因爲BitBlt()方法沒有正確使用標題欄(除非您知道如何做)。
可以正常工作了整個窗口的當前的代碼是:
HWND hParentWindow = GetActiveWindow();
RECT rc;
GetWindowRect(hParentWindow, &rc);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
//create
HDC hdcParent = GetDC(NULL);
HDC hdc = CreateCompatibleDC(hdcParent);
HBITMAP hBmp = CreateCompatibleBitmap(hdcParent, width, height);
SelectObject(hdc, hBmp);
//Print to memory hdc
PrintWindow(hParentWindow, hdc, 0);
//copy to clipboard
OpenClipboard(NULL);
EmptyClipboard();
SetClipboardData(CF_BITMAP, hBmp);
CloseClipboard();
// Save it in a file:
saveBitmap(ofn.lpstrFile, hBmp);
//release
DeleteDC(hdc);
DeleteObject(hBmp);
ReleaseDC(NULL, hdcParent);
我如何保存位圖裁剪?
是剪貼板代碼工作 – StackHeapCollision 2014-09-23 12:31:05
OK - 心存疑慮去除款 – 2014-09-23 12:41:11