C++ 如何使用CImage正确加载灰度BMP的字符数组?
我有以下代码:C++ 如何使用CImage正确加载灰度BMP的字符数组?,c++,c,image,visual-c++,bmp,C++,C,Image,Visual C++,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.GetWidt
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];
}
cout首先要检查的是input.Load()
是否成功。它返回一个HRESULT
,您应该检查它的值。这将是一个关于发生了什么的线索
您可以在此处解释HRESULT的含义:
祝你好运,但还需要更多的信息
编辑后:此外,您只能对DIB节使用CImage::Load()。查看此链接了解更多信息:首先要检查的是input.Load()
是否成功。它返回一个HRESULT
,您应该检查它的值。这将是一个关于发生了什么的线索
您可以在此处解释HRESULT的含义:
祝你好运,但还需要更多的信息
编辑后:此外,您只能对DIB节使用CImage::Load()。有关详细信息,请参阅此链接:图像文件不在您期望的目录中?图像与程序位于同一目录中,加载图像时没有问题。图像文件不在您期望的目录中?图像与程序位于同一目录中,加载图像时没有问题。