我有以下代码正常工作,它将我的应用程序上的活动窗口的快照放入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