从现有的缓冲区创建一个HBITMAP [英] Creating a HBITMAP from an existing buffer

查看:624
本文介绍了从现有的缓冲区创建一个HBITMAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的缓冲器满(DIB)位图数据,即宽x高x 4的大小字节(RGBA)。我想要做的是提请本位图屏幕,但看CreateBitmap ... / CreateDIB ...功能,他们似乎并没有做什么,我要找的。我不想,我想保留访问它复制的记忆,这样我就可以继续写它在下一帧(不招致罚款复制数据)。请问这样的方法存在,或者我必须创建一个新的位图,并呼吁它SetDIBits?

I have an existing buffer full of (DIB) bitmap data, i.e. width x height x 4 bytes (RGBA) in size. What I want to do is draw this bitmap to the screen, but looking at the CreateBitmap... / CreateDIB... functions, they don't appear to do what I'm looking for. I don't want to copy the memory in, I want to retain access to it, so I can continue to write to it in the next frame (without incurring a penalty for copying the data). Does such a method exist, or do I have to create a new bitmap and call SetDIBits on it?

推荐答案

如果你想简单的code,那么你可以使用位图的结构和分配给它的bmBits指向您的实际图像数据(RGBA 8位)

If you want simple code, then you can use a BITMAP structure and assign it's bmBits to point to your actual image data (RGBA 8-Bit).

然后你可以使用GDI方法

Then you can use GDI method

HBITMAP CreateBitmapIndirect(const BITMAP *pbm);

创建HBITMAP的图像显示屏幕。

to create HBITMAP for displaying the image to screen.

但实际上我认为系统仍然进行复制,同时创造HBITMAP,这就是为什么CreateBitmapIndirect返回后,就可以安全自由的图像数据。

But actually I think the system still do the copying while creating HBITMAP, that's why after CreateBitmapIndirect returns, you can safely free your image data.

但至少你只需要一次创建的缓冲区,并重复使用它,只要图像的大小不发生变化。

But at least you only have to create the buffer once, and using it repeatedly as long as the size of the image doesn't change.

我用这个方法从RED的摄像头显示的原始视频。

I use this method to display raw video from RED's Camera.

这篇关于从现有的缓冲区创建一个HBITMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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