Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HBITMAP to BITMAP converting

Tags:

bitmap

winapi

Can't understnand what is wrong with this code:

HBITMAP bm = 0; 
BITMAP Bitmap;
bm = (HBITMAP)LoadImage (0, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
int error = GetObject( &Bitmap, sizeof( BITMAP  ), &bm );

The LoadImage function returns non null pointer. However GetObject returns 0, which indicates on error. I want to get size info and image data from HBITMAP pointer (the pointer can be passed as parameter, so I can't change the way I load the bitmap file).

like image 489
maximus Avatar asked Dec 27 '12 07:12

maximus


1 Answers

Maybe putting the parameters in the right places will help:

HBITMAP bm = 0; 
BITMAP Bitmap;
bm = (HBITMAP)LoadImage (0, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
int error = GetObject( bm, sizeof( BITMAP ), &Bitmap ); // << NOTE ORDERING

See the documentation on GetObject() for more info.

like image 154
WhozCraig Avatar answered Sep 28 '22 07:09

WhozCraig