如何在C ++中从HBITMAP创建IBuffer?

时间:2017-11-05 19:48:21

标签: c++ winapi c++-cx

我有代码,制作屏幕截图,并将其保存到HBITMAP

GetClientRect(hwnd, &rc);
HDC hdcScreen = GetDC(NULL);
HDC hdc = CreateCompatibleDC(hdcScreen);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
HBITMAP hbmp = CreateCompatibleBitmap(hdcScreen,width, height);
SelectObject(hdc, hbmp);
PrintWindow(hwnd, hdc, PW_CLIENTONLY);  

然后,我想从 hbmp 对象

创建新的缓冲区(windows.storage.streams.buffer)类实例
Buffer obj = new Buffer(hbmp); // HOW TO DO SOMETHING LIKE THIS ???
SoftwareBitmap^ softwareBitmap = SoftwareBitmap::CreateCopyFromBuffer(obj ,
BitmapPixelFormat::Bgra8, width, height);

主要目标 - 将窗口的屏幕截图保存到SoftwareBitmap对象

0 个答案:

没有答案