# WinAPI - LoadImage sometimes crashes

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

## 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,

if (!hImage)
return;

DIBSECTION dibSection;
GetObject(hImage,sizeof(DIBSECTION),&dibSection);
if (dibSection.dsBm.bmBitsPixel == 1) cout << "only consits of one pixe"<<endl;

Thanks a lot!!!

##### Share on other sites
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.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633721
• Total Posts
3013532
×