使用CreateBitmapFromHBITMAP工厂方法从HBITMAP生成IWICBitmap很容易。但是如何从IWICBitmapSource获取简单的GDI位图?

最佳答案

不幸的是,无法将IWICBitmap转换为HBITMAP或从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());

关于c++ - 如何将IWICBitmapSource转换为HBITMAP?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17602548/

10-14 05:48