News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

LoadImage

Started by Jimg, January 10, 2009, 09:37:32 PM

Previous topic - Next topic

Jimg

I'm getting an error loading the attached bitmap, test1.bmp


There is no actual error returned with GetLastError, so I'm curious what is wrong with this bitmap that it won't load but gives no error.  I can load it with any bitmap editor without a problem, just not with LoadImage.  It comes from windows' cards.dll

my test program:
.nolist
include masm32rt.inc
.list
.data
cname1 db "test1.bmp",0    ; this one won't load
cname2 db "test2.bmp",0    ; this one no problem
.code
program:
    invoke LoadImage,0,addr cname1,IMAGE_BITMAP,0,0,LR_LOADFROMFILE
    .if eax==0
        mov eax,LastError$()
        print eax,13,10
        inkey "error loading card"
    .else
        inkey "success"
    .endif
    ret
end program

[attachment deleted by admin]

jj2007

Odd indeed. The attached version runs fine. If you compare against the failing one, you will see some tiny differences in the header area...

[attachment deleted by admin]

Jimg

Here's another one that absolutely won't load with LoadImage.  Is there some other api to load these bitmaps?

[attachment deleted by admin]

Vortex

Hi Jimg,

The routines below are supplied with the Masm32 package :

QuoteBitmapFromFile
BitmapFromResource
BitmapFromMemory

Raymond coded a library to load images :

http://www.masm32.com/board/index.php?topic=9538.0

Third, you can use GDI+ to load and view images.

Jimg

So, for these to even exist, there must be something intrinsically wrong with the LoadImage api?

RotateRight

Jimg,

Take a look at "test1.bmp" in a hex editor.
At zero based offset 34 change the two bytes
0xB0 and 0x04 to zeros. (The 35th and 36th
byte in the file).

Run your test program again.  Did it work?

This is biSizeImage from the BITMAPINFOHEADER.

The docs say this:

"Specifies the size, in bytes, of the image.
This may be set to zero for BI_RGB bitmaps.
Windows 98/Me, Windows 2000/XP:
If biCompression is BI_JPEG or BI_PNG,
biSizeImage indicates the size of the
JPEG or PNG image buffer, respectively."

Perhaps LoadImage thinks that the image is
compressed since there is a value here?

Also, does the superseded function LoadBitmap work?

Think you could share which graphic tool you are
using so I won't use it? :lol

Mark

Jimg

Quote from: RotateRight on January 13, 2009, 04:05:17 AM
Jimg,

Take a look at "test1.bmp" in a hex editor.  At zero based offset 34 change the two bytes 0xB0 and 0x04 to zeros. (The 35th and 36th byte in the file).

Run your test program again.  Did it work?

This is biSizeImage from the BITMAPINFOHEADER.

The docs say this:

"Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. Windows 98/Me, Windows 2000/XP:
If biCompression is BI_JPEG or BI_PNG,
biSizeImage indicates the size of the
JPEG or PNG image buffer, respectively."

Perhaps LoadImage thinks that the image is compressed since there is a value here?

Also, does the superseded function LoadBitmap work?

Think you could share which graphic tool you are using so I won't use it? :lol

Mark

Thank you for your reply and the time you spent researching this problem. :U
I got these bmps from extracting them from windows cards.dll using resource hacker.  Probably mistake number one.  What can I expect stealing from microsoft? :wink
It just surprises me that a bitmap can be loaded with every other tool I tried except the api meant to load bitmaps.  Ultimately I gave up and loaded the troublesome bitmaps in Darrel Lemke's ABitmapEditor and just saved them without changes, which cleared up any problems with the loadimage api.  I posted this last message after screwing around for hours trying to write a simple program to read and use some bitmaps.  I guess the user will have to be sure the bitmap he feeds the program is valid.  I really should have calmed down a bit first.
Thanks again for finding the problem and the solution.

Jim