如何将 IWICBitmapSource 转换为 HBITMAP? [英] How to covert IWICBitmapSource to HBITMAP?

查看:32
本文介绍了如何将 IWICBitmapSource 转换为 HBITMAP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

遗憾的是没有办法将 IWICBitmap 转换为 HBITMAP,或者从IWICBitmapSource.但是,如果格式与 CreateBitmap 期望的格式兼容,您可以轻松地从像素缓冲区创建 HBITMAP.

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.

假设是 32 位 RGBA 位图:

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

这篇关于如何将 IWICBitmapSource 转换为 HBITMAP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆