如何使用 CImage 正确加载灰度 BMP 的字符数组?

发布于 2024-11-02 15:14:29 字数 717 浏览 2 评论 0原文

我有以下代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2024-11-09 15:14:29

首先要检查的是 input.Load() 是否成功。它返回一个 HRESULT,您应该检查它的值。这将是关于正在发生的事情的线索。

链接到 CImage::Load()

您可以解释 HRESULT 的含义此处:

有关 HRESULT 的详细信息

祝你好运,但还需要更多信息。

编辑后:此外,您只能对 DIB 部分使用 CImage::Load() 。有关详细信息,请参阅此链接:CImage 类参考

First thing to check is that input.Load() is successful. It returns an HRESULT 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文