Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Loading a 32 bit Bitmap

瀏覽次數:956 次
跳到第一則未讀訊息

Matt

未讀,
2003年2月20日 下午1:58:252003/2/20
收件者:
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

未讀,
2003年2月20日 下午6:03:372003/2/20
收件者:
> 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]

未讀,
2003年2月20日 下午6:17:022003/2/20
收件者:
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

未讀,
2003年2月21日 下午2:16:352003/2/21
收件者:
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]

未讀,
2003年2月27日 中午12:51:132003/2/27
收件者:
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 則新訊息