LoadImage Problem

T

TEST

I am saving images out from a camera to bmp using directshow. I can open
these images in mspaint or any other image program without a problem.

Using:
HBITMAP h_Bitmap;
h_Bitmap = (HBITMAP)LoadImage(hInstance, L"C:\\DELETE\\1.bmp", IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE);

h_Bitmap is staying null. GetLastError is returning 0. I can successfully
load a bitmap created with mspaint without a problem using the method above
so I have to think their is something extra inside the bitmap cauing issues.
Looking at the properties of a mspaint bitmap and the one I exported the
only differences I see is that Bit Depth is 32 for the camera and 24 for the
one using mspaint.


I can also load these bitmaps with managed code like

Bitmap obj_Bitmap1 = Bitmap::FromFile("C:\\DELETE\\1.bmp");
mobj_PictureBox->Image = Image::FromHbitmap(obj_Bitmap1.GetHbitmap());

which works fine. Any idea's why this would happen or how I can go about
fixing or finding out whats going on?
 
T

TEST

Thanks for the reply Dave.

Tried it with NULL also. Same result. It acts like its loading fine
w/getlasterror returning 0. Any other idea?
 
T

TEST

Got it. I was somehow corrupting the bitmap when I wrote it to disk. This
has been corrected. FYI 5 years from now when someone pulls this, I found
out for sure by checking the bitmapfileheader

FILE *file;
file = fopen("C:\\imaging\\result.bmp", "rb");
BITMAPFILEHEADER bitmapFileHeader;
size_t read = fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, file);
fclose(file);

bfType should be 19778 per the doc's
http://msdn.microsoft.com/en-us/library/ms532321.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top