I just want to get how many pixel does my picture measure ?
I'm using a .RES file and i make a compatible Device Context but i don't find which API to use in order to get back the width & height of my bitmap... Could u help me please ?
Posted on 2001-12-25 15:38:15 by Kheo
take a look at the BITMAPINFO:

typedef struct tagBITMAPINFO { // bmi
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO;

typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;

typedef struct tagRGBQUAD { // rgbq
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;

here you will find everything you need!
Posted on 2001-12-25 17:30:39 by adapix
By bizzare coincidence I was just writing some code to do that. Heres the important bit.

LOCAL bit:BITMAP,tBm

invoke LoadBitmap,hIst,rId
mov tBm,eax
invoke GetObject,tBm,sizeof(BITMAP),addr bit

And that will fill out the following structre with the necessary info:

typedef struct tagBITMAP { // bm
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
} BITMAP;
Posted on 2001-12-25 18:06:42 by Eóin
E?in,

> LOCAL bit:BITMAP,tBm
>
> invoke LoadBitmap,hIst,rId
> mov tBm,eax
> invoke GetObject,tBm,sizeof(BITMAP),addr bit

I prefer using "sizeof tBm" instead of using the size of a fixed type, becuase if for some reason you change the type of btBm you won't need to make any modifications to your code. This is significant when the size of your code increases.

Don't forget to check the return value of LoadBitmap() and GetObject() !!!!
Posted on 2001-12-25 19:04:35 by Boggy
I think you ment to say sizeof(bit) rather than tBm, probably just a typo.

And yes you have a good point, in the case where we only and the width and height of the bitmap its more effecient to discard the rest of the BITMAP structre. We need only fill up the first three members of the structre.

LOCAL bmType,bmWidth,bmHeight,tBm
invoke LoadBitmap,hIst,rId
mov tBm,eax
invoke GetObject,tBm,12,addr bmType

Since the API will only fill out the first 12 bytes of the structre it won't go past bmHeight.
Posted on 2001-12-26 06:45:28 by Eóin
> I think you ment to say sizeof(bit) rather than tBm, probably just a typo.

No typo, that's what I intended to write. I'm against redundant syntax unless
it makes the code clearer; adding opening and a closing paretheses around a
data type and shoving it next to its operater is redundant (and messy) IMO.

sizeof bit

Is cleaner and expresses exactly what I want.

> And yes you have a good point, in the case where we only and the width and
> height of the bitmap its more effecient to discard the rest of the BITMAP
> structre. We need only fill up the first three members of the structre.
>
> LOCAL bmType,bmWidth,bmHeight,tBm
> invoke LoadBitmap,hIst,rId
> mov tBm,eax
> invoke GetObject,tBm,12,addr bmType
>
> Since the API will only fill out the first 12 bytes of the structre it won't go past bmHeight.

Ah, but what if a LONG suddenly becomes 8 bytes in size?! Better to use an
EQUATE and calculate the size of each of the structure members with sizeof.
The point is: don't hard code your values.

Boggy
Posted on 2001-12-26 11:17:51 by Boggy
I wasn't pointing out the lack of paretheses, I was pointing out that you wrote tBm instead of bit ;)

And as it happens I rarely hard code my values when dealing with my own structres. But when dealing with windows ones, they won't change during the development of an app so if I see benifits in doing so I'll hard code them. If they change afterwards well your screwed either way, once compiled all equates are hardcoded. :grin:
Posted on 2001-12-26 11:31:28 by Eóin
Hallo,

GetObject() don't work under Windows XP !!! I don't know why...
You can use GetDIBits() to get the width and height and many other picturedatas

Greetings, Nordwind
Posted on 2001-12-26 12:45:53 by Nordwind64
Nordwind64: It should work in winXP, at least it works in win2k. This is what msdn says:


Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Wingdi.h; include Windows.h.
Library: Use Gdi32.lib.
Unicode: Implemented as Unicode and ANSI versions on
Windows NT/2000/XP. Also supported by Microsoft Layer
for Unicode.


Thomas
Posted on 2001-12-26 16:47:39 by Thomas
Hallo,

Thomas: My Assembler-Game-Dll ProSpeed had used GetObject(), but under XP GetObject() don't work. I have made many tests, but GetObject only return 0. A Windows XP bug? I don't know. Now I use GetDIBits instead of GetObject...

Nordwind
Posted on 2001-12-27 04:33:58 by Nordwind64
Strange... should be a bug then as msdn says it is compatible with winXP...

Thomas
Posted on 2001-12-27 11:43:05 by Thomas