News:

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

BitmapFromFile

Started by korte, May 11, 2007, 09:16:24 AM

Previous topic - Next topic

korte


Using bitmapfromfile lib(masm32).
Displayiong jpeg file.

how to determinate picture original width and height?


MichaelW

Starting with the HBITMAP returned by BitMapFromFile, I think you can get the dimensions by calling the GDI GetObject function, but I'm not sure how the bitmap dimensions relate to the "original" dimensions.
eschew obfuscation

zooba

Alternatively, GetDIBits will fill in a BITMAPINFO structure (the data pointer is optional). Whether or not you get better results than with GetObject I don't know, but I've had trouble in the past with GetObject. Hopefully GetDIBits will give the right numbers, since you are supposed to be able to use them to allocate memory for the bitmap.

Cheers,

Zooba :U

sinsi

You could also read the original jpeg's header, since you know the filename...
Light travels faster than sound, that's why some people seem bright until you hear them.

korte

Quote from: MichaelW on May 11, 2007, 10:07:48 AM
Starting with the HBITMAP returned by BitMapFromFile, I think you can get the dimensions by calling the GDI GetObject function, but I'm not sure how the bitmap dimensions relate to the "original" dimensions.

NOT work.

   invoke   BitmapFromFile,eax
   mov   hBitmap,eax
   invoke   GetObject,hBitmap,sizeof(BITMAP),addr xbitmap  <- returned 0
   invoke   GetLastError <- returned 0


hBitmap correct object
displaying ok.

korte

also not work



   invoke    GetDIBits,hMemDC,hBitmap,0,128,NULL,addr xbitmapinfo,DIB_RGB_COLORS
   invoke    GetLastError



but displaying correct

   invoke   BitBlt,hdc,0,0,128,128,hMemDC,0,0,SRCCOPY

MichaelW

Try calling GetObject with lpvObject set to NULL, then compare the return value, which should be the required size of the buffer, to the size of the buffer you are passing.
eschew obfuscation

korte


zooba

Works for me. Probably you forgot to set the biSize value:

mov xbitmapinfo.bmiHeader.biSize, SIZEOF BITMAPINFOHEADER

I also used GetDC(0) (ie. the desktop window) for my DC since I didn't create any windows.

GetObject also worked for me, though I have had it fail at other times.

Both gave me the correct pixel dimensions of the JPEG image I loaded.

Cheers,

Zooba :U

korte

mov xbitmapinfo.bmiHeader.biSize, SIZEOF BITMAPINFOHEADER


yes.
work
thx