开发者

How do I correctly load the char array of a grayscale BMP using CImage?

开发者 https://www.devze.com 2023-02-27 13:34 出处:网络
I have the following code: cout<<\"Please enter the name of your BMP image file: \"<<endl;

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 sp开发者_如何学JAVAace 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!

: )


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

0

精彩评论

暂无评论...
验证码 换一张
取 消