Jump to content
  • Advertisement
Sign in to follow this  
dali

WinAPI - LoadImage sometimes crashes

This topic is 4156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I use the LoadImage function from the WinAPI to load images. Most of the time LoadImage works correct but sometimes the bits per pixels are wrong it is said that the image only consits of 1 bit per pixel although it consists of 24. The weired thing is that I always load the same image so there shouldnt be the error sometimes. Where could go wrong?
HBITMAP hImage = (HBITMAP) LoadImage(NULL,
		filename,
		IMAGE_BITMAP,
		0,
		0,
		LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTCOLOR);

// Could not load bitmap
if (!hImage) 
    return;

// Get info about bitmap
DIBSECTION dibSection;
GetObject(hImage,sizeof(DIBSECTION),&dibSection);
if (dibSection.dsBm.bmBitsPixel == 1) cout << "only consits of one pixe"<<endl; 
Thanks a lot!!!

Share this post


Link to post
Share on other sites
Advertisement
The docs for GetObject indicate that the DIBSECTION structure is used with bitmaps returned from CreateDIBSection. Try using the BITMAP structure instead. I realize that the first member of the DIBSECTION structure is a BITMAP structure, but that's what I'd try first just the same - even though you specified LR_CREATEDIBSECTION in the LoadImage call.

See also HOWTO: How To Use LoadImage() to Read a BMP File

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!