Question

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

Était-ce utile?

La solution

Unfortulately there is no way to convert a IWICBitmap to a HBITMAP, or to get one from a IWICBitmapSource. You could, however, easily create the HBITMAP from a pixel buffer if the format is compatible with what CreateBitmap expects.

Assuming a 32-bit RGBA bitmap:

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());

Autres conseils

There's no guarantee that behind the scenes IWICBitmapSource even uses a GDI bitmap. You can access the raw bits using the IWICBitmap::Lock method, but if you want to use the bitmap with GDI functions I think you will need to create a GDI bitmap and copy the bits to it yourself.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top