如何使用 CImage 正确加载灰度 BMP 的字符数组?
我有以下代码:
cout<<"Please enter the name of your BMP image file: "<<endl;
cin>>fname;
nP = fname.c_str();
CImage input = CImage();
input.Load(nP);
// allocate space for host source image
unsigned char *pHI, *pCI;
width = input.GetWidth();
height = input.GetHeight();
pCI = (unsigned char *)input.GetBits();
pHI = (unsigned char *)malloc(sizeof(unsigned char) * width * height);
// fill array with CImage array content
srand (time(NULL));
for (int cnt = 0; cnt < sizeof(unsigned char) * width * height; cnt++){
pHI[cnt] = pCI[cnt];
}
但是当我尝试获取宽度和高度时,程序给了我一个错误。
“调试断言失败!...表达式:m_hBitmap!=0”
如果您对可能导致此问题的原因/我应该更改什么有任何想法,我将不胜感激!
:)
I have the following code:
cout<<"Please enter the name of your BMP image file: "<<endl;
cin>>fname;
nP = fname.c_str();
CImage input = CImage();
input.Load(nP);
// allocate space for host source image
unsigned char *pHI, *pCI;
width = input.GetWidth();
height = input.GetHeight();
pCI = (unsigned char *)input.GetBits();
pHI = (unsigned char *)malloc(sizeof(unsigned char) * width * height);
// fill array with CImage array content
srand (time(NULL));
for (int cnt = 0; cnt < sizeof(unsigned char) * width * height; cnt++){
pHI[cnt] = pCI[cnt];
}
But the program gives me an error when I try to get the width and height.
"Debug Assertion Failed! ... Expression: m_hBitmap !=0"
If you have any ideas as to what could be causing this / what I should change, I'd appreciate the help!
: )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先要检查的是
input.Load()
是否成功。它返回一个HRESULT
,您应该检查它的值。这将是关于正在发生的事情的线索。链接到 CImage::Load()
您可以解释 HRESULT 的含义此处:
有关 HRESULT 的详细信息
祝你好运,但还需要更多信息。
编辑后:此外,您只能对 DIB 部分使用 CImage::Load() 。有关详细信息,请参阅此链接:CImage 类参考
First thing to check is that
input.Load()
is successful. It returns anHRESULT
and you should check the value of this. It's going to be a clue as to what's going on.Link to CImage::Load()
You can interpret what an HRESULT means here:
Details on HRESULT
Good luck, but more information is needed.
After edit: Further more, you can only use CImage::Load() for DIB sections. See this link for more info: CImage class reference