Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading a 32 bit Bitmap

961 views
Skip to first unread message

Matt

unread,
Feb 20, 2003, 1:58:25 PM2/20/03
to
Hey all,

Is there a way I can load a 32bit bitmap in XP? LoadImage doesn't seem to
work on them. I can load the image into Paint, but I can't seem to get it
into my program.

Any help would be appreciated.

Matt


Mike D Sutton

unread,
Feb 20, 2003, 6:03:37 PM2/20/03
to
> Is there a way I can load a 32bit bitmap in XP? LoadImage doesn't seem to
> work on them. I can load the image into Paint, but I can't seem to get it
> into my program.

Many of the .BMP loading functions don't like 32-bit .BMP's since they're
not part of the original specification, so generally you have to write
support for these yourself. Luckily the .BMP format is very simple since
it's just a DIB with an extra header at the start.
Open the file in binary mode, then read a 14-byte BITMAPFILEHEADER structure
and validate it's "bfType" member to be ASCII "BM" or 0x4D42 (The Bitmap
'Magic cookie')
Next, read in a 40-byte BITMAPINFOHEADER structure and make sure that the
"biSize" = 40, "biBitCount" = 32 and "biCompression" = 0. If that's ok,
then create a DIBSection using the height and width from this structure at
32-bit, then read in ((Width * 4) * Height) bytes from the file into it.
Hope this helps,

Mike


-- EDais --

- Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/
Work E-Mail: ED...@btclick.com
Other E-Mail: Mike....@btclick.com


John Hornick [MS]

unread,
Feb 20, 2003, 6:17:02 PM2/20/03
to
Hi,


LoadImage() should load 32bpp BMPs - can you share with us one such
BMP that LoadImage() won't load? And what does GetLastError() tell
you when LoadImage() fails?

Also, you might consider using GDI+ for your imaging needs.

Thanks,
- John
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Visit http://www.microsoft.com/security for current information on security.

Matt

unread,
Feb 21, 2003, 2:16:35 PM2/21/03
to
When I call GetLastError() after the call to LoadImage(), it returns 0 and
the bitmap returned by LoadImage is NULL;

Maybe I'm using an incorrect parameter? I'm calling:

HBITMAP hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
DWORD dwErr = GetLastError();

The image I've been working with was exported from Photoshop as a 32bit
bitmap.
Unfortunately, GDI+ isn't an option since most of our distribution is
online.

Thanks for the help,

Matt


"John Hornick [MS]" <JHor...@online.microsoft.com> wrote in message
news:Se9ynYT2CHA.536@cpmsftngxa06...

John Hornick [MS]

unread,
Feb 27, 2003, 12:51:13 PM2/27/03
to
Hi,

> When I call GetLastError() after the call to LoadImage(), it returns 0 and
> the bitmap returned by LoadImage is NULL;
>
> Maybe I'm using an incorrect parameter? I'm calling:
>
> HBITMAP hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
> MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
> DWORD dwErr = GetLastError();
>
> The image I've been working with was exported from Photoshop as a 32bit
> bitmap.
> Unfortunately, GDI+ isn't an option since most of our distribution is
> online.


Try loading the same BMP with LR_LOADFROMFILE. If you can load it from
file, but not from a resource, then there must be something wrong with
the resource handling - maybe the instance handle.

On the other hand, if you can't load that image from a file either, then
maybe there's something up with it, and I'd repeat my request for you
to share one such image with us.

0 new messages