Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用CImage正确加载灰度BMP的字符数组?_C++_C_Image_Visual C++_Bmp - Fatal编程技术网

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()。有关详细信息,请参阅此链接:

图像文件不在您期望的目录中?图像与程序位于同一目录中,加载图像时没有问题。图像文件不在您期望的目录中?图像与程序位于同一目录中,加载图像时没有问题。