Nicholas Fresta
Nicholas Fresta

Reputation: 11

A bitmap gets loaded, another bitmap doesn't. LoadImage() from Windows.h

I have two bitmaps. The first one is named BM1, the second one is named BM2.
I wrote this line of code in the WM_CREATE message case:

HBITMAP hImage = (HBITMAP)LoadImage(GetModuleHandle(NULL), "C://Projects/BM1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

If i attempt to load BM1, it works.
If i attempt to load BM2, the function returns NULL.

This is the difference in the data of those images:
BM1 (the good one) is 34 x 34. Bit depth 4. Size 798 bytes.
BM2 (the bad one) is 272 x 290. Bit depth 24. Size 234 kilobyte (It was a png and i converted it to bmp).

I assume the problem is (almost) obviously related to the bit depth, but i would like to understand why. I'm using the x64 configuration.

Upvotes: 1

Views: 138

Answers (1)

Torrecto - MSFT
Torrecto - MSFT

Reputation: 640

As IInspectable said: The core issue is in the tool you used to convert BM2 failing to produce a valid BMP file.

You can convert it to BMP file by Microsoft Paint correctly. enter image description here

You can set depth in here.

enter image description here

Upvotes: 1

Related Questions