2

It's easy to produce IWICBitmap from HBITMAP with CreateBitmapFromHBITMAP factory method. But how to get simple GDI bitmap from IWICBitmapSource?

4

2 回答 2

4

不幸的是,没有办法将 a 转换IWICBitmap为 a HBITMAP,或者从 a 中得到一个IWICBitmapSource。但是,如果格式与预期HBITMAP兼容,您可以轻松地从像素缓冲区创建。CreateBitmap

假设一个 32 位 RGBA 位图:

IWICBitmapSource *bitmap_source = some_func();

UINT width = 0, height = 0;
bitmap_source->GetSize(&width, &height);

std::vector<BYTE> buffer(width * height * 4);
bitmap_source->CopyPixels(0, width * 4, buffer.size(), buffer.data());

HBITMAP bitmap = CreateBitmap(width, height, 1, 32, buffer.data());
于 2013-07-25T19:34:34.900 回答
1

不能保证在幕后IWICBitmapSource甚至使用 GDI 位图。您可以使用该IWICBitmap::Lock方法访问原始位,但如果您想将位图与 GDI 函数一起使用,我认为您需要创建一个 GDI 位图并将这些位复制到其中。

于 2013-07-11T20:14:24.217 回答