gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 04:06:05 24 4
gpt4 key购买 nike

我有以下代码:

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”

如果您对可能导致此问题的原因/我应该更改的内容有任何想法,我将不胜感激!

: )

最佳答案

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

Link to CImage::Load()

您可以在这里解释 HRESULT 的含义:

Details on HRESULT

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

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

关于c++ - 如何使用 CImage 正确加载灰度 BMP 的字符数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5749382/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com