正确使用CreateDIBSection? [英] using CreateDIBSection correctly?

查看:145
本文介绍了正确使用CreateDIBSection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候全部,



我的变量中有一段代码和一个位图的内存缓冲区:

my_symbol->位图



我试图显示这个但不想保存&从文件中读取或使用太慢的SetPixel&有重大的性能问题。我不确定位图本身是否包含标题,但是图像显示不正确,位图是倾斜的并且没有正确显示,我的直觉表示代码在显示图像时是正确的,但是有些不对与渲染,也许是记忆或其他东西,不确定,任何想法?



谢谢,

Shirzad



Greetings All,

I have this piece of code and an in memory buffer of a bitmap in my variable:
my_symbol->bitmap

I am trying to display this but dont want to save & read from file or use SetPixel which is too slow & has major performance issues. I am not sure if the bitmap itself includes a header or not, but the image is displayed incorrectly, the bitmap is slanted and is not showing up properly, my gut feeling says that the code is correct in displaying the image, however something is incorrect with the rendering, maybe the memcopy or something else, not sure, any ideas?

Thanks,
Shirzad

void *bits = (unsigned char*)(my_symbol->bitmap);
HBITMAP hBitmap = CreateDIBSection(pDC->GetSafeHdc(), &info, DIB_RGB_COLORS, (void **)&pDestData, NULL, 0);
memcpy(pDestData, my_symbol->bitmap, info.bmiHeader.biSizeImage);

推荐答案

倾斜是一个问题aligment。位图必须在位图的每一行中与DWORD对齐。这是输入数据中的一个问题。
Slanted is a problem of aligment. Bitmaps have to be DWORD aligned in every line of the bitmap. It is a problem in your input data.


如果位图包含标题,则必须跳过它(你可能需要从中获取一些信息)。并且,正如 KarstenK 所建议的那样,你必须考虑 stride (参见 MSDN上的BITMAPINFOHEADER结构 [ ^ ]。

我建议你测试一下具有众所周知(和'表现良好')简单位图文件的代码。
If the bitmap contains the header you have to skip it (well you probably have to get some info from it). And, as suggested by KarstenK, you have to consider the stride (see BITMAPINFOHEADER structure at MSDN[^].
I suggest you to test your code with well known (and 'well behaved') simple bitmap files.


这篇关于正确使用CreateDIBSection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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