Any good soul could help me out here. I need to get the width and height of an image, but I can reach the bitmap structure with what I got from searching the forum. Yep, very nooby.. but I really need to get this done quickly:
inv CreateCompatibleDC,hdc
mov hCpDC, eax
inv LoadBitmap, hInstance, IDB_CP
inv SelectObject, hCpDC, eax
lea edi, [ ???? +sizeof(BITMAPFILEHEADER)]
mov ebx, BITMAPINFOHEADER.biWidth[edi]
mov edx, BITMAPINFOHEADER.biHeight[edi]
I really thank any help
Cheers
Try this:
invoke GetCurrentObject, hDC, OBJ_BITMAP
invoke GetObject, eax, BITMAP, addr bitmap
print str$(bitmap.bmWidth), " is the width"
.data
bm BITMAP <>
.code
invoke GetObject, rv(LoadBitmap,rv(GetModuleHandle,0),IDB_CP),sizeof BITMAP, addr bm
printf("\n Width=%d,Height=%d ",bm.bmWidth,bm.bmHeight)
similar to what Jochen suggested :P
LOCAL hbmpCp :HBITMAP
LOCAL bmpCp :BITMAP
;------------------------------------------------
INVOKE LoadBitmap,hInstance,IDB_CP
mov hbmpCp,eax
INVOKE SelectObject,hCpDC,eax
INVOKE GetObject,hbmpCp,sizeof BITMAP,addr bmpCp
mov ecx,bmpCp.bmWidth ;ECX = image width
mov edx,bmpCp.bmHeight ;EDX = image height
GetObject function
https://msdn.microsoft.com/en-us/library/dd144904(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/dd144904(v=vs.85).aspx)
BITMAP structure
https://msdn.microsoft.com/en-us/library/dd183371(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/dd183371(v=vs.85).aspx)
GetObject returns information based on the type of handle that is passed
if you don't have the correct information size for that handle type, it will return error
That information is part of the file header.
So, you can use the Microsoft abstract and C++-inspired way or handling graphic files, SelectObject GetObject, etc, or or can roll your sleeves and look directly learning something in the process.
There is an essay here:
http://masm32.com/board/index.php?topic=6733.0
Thanks guys, I really mean it!
It's working!
Hey aw27, I'm a rolling sleeves kind of guy! Sometimes, you learn a lot when you ask a question and people teach you the way, and you go from there.
Unfortunately I've got a son that needs extra care, along with my day job. Without such a help from you guys, I could never evolve in assembly (maybe I wouldn't even be coding).
Quote
Unfortunately I've got a son that needs extra care, along with my day job.
I have a large experience with that and my son related dramas are far from over.
What I meant with rolling the sleeves is "not be afraid of plunging in the dirty waters" as opposed to "not be afraid of working like a horse".
Quote from: aw27 on March 28, 2018, 04:46:35 PM
Quote
Unfortunately I've got a son that needs extra care, along with my day job.
I have a large experience with that and my son related dramas are far from over.
What I meant with rolling the sleeves is "not be afraid of plunging in the dirty waters" as opposed to "not be afraid of working like a horse".
Ok! Thanks
does it also work if you want to use a .jpg,.gif etc?
its easier to make something small with help of .jpgs, so I dont break the forum limit
I wonder if its possible to emulate old games that uses palette tricks, by Reading in a 8bit bitmap and change its palette data and use bitblt to output it?
it can be done with a regular bitmap image
however, it is much easier to change the palette if you load the image as a DIB section
i have done this using 256-color images (not as effective with other types)
to load the image as a DIB section, use LoadImage with the LR_CREATEDIBSECTION flag
LoadImage
https://msdn.microsoft.com/en-us/library/ms648045(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/ms648045(v=vs.85).aspx)
then, in addition to using GetObject as mentioned before, you can use...
GetDIBColorTable
https://msdn.microsoft.com/en-us/library/dd144878(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/dd144878(v=vs.85).aspx)
SetDIBColorTable
https://msdn.microsoft.com/en-us/library/dd162972(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/dd162972(v=vs.85).aspx)
notice, that with a DIB section, GetObject may be used to fill either a BITMAP or a DIBSECTION structure
GetObject
https://msdn.microsoft.com/en-us/library/dd144904(v=vs.85).aspx (https://msdn.microsoft.com/en-us/library/dd144904(v=vs.85).aspx)
DIBSECTION
https://msdn.microsoft.com/en-us/library/dd183567%28v=vs.85%29.aspx (https://msdn.microsoft.com/en-us/library/dd183567%28v=vs.85%29.aspx)
BITMAP
https://msdn.microsoft.com/en-us/library/dd183371%28v=vs.85%29.aspx (https://msdn.microsoft.com/en-us/library/dd183371%28v=vs.85%29.aspx)
by the way, JPG and GIF files are very different from BMP's
i don't know, LoadImage might support one or both (i doubt it)
if so, it will load the image as a bitmap, though
it always returns a handle to a bitmap
Quote from: dedndave on March 28, 2018, 11:37:07 PM
by the way, JPG and GIF files are very different from BMP's
i don't know, LoadImage might support one or both (i doubt it)
if so, it will load the image as a bitmap, though
it always returns a handle to a bitmap
Right. I normally use GdipCreateBitmapFromStream, and it doesn't care what format the buffer provides. So GetObject works fine with JPG, PNG & friends.
Quote from: jj2007 on March 29, 2018, 12:42:33 AM
Quote from: dedndave on March 28, 2018, 11:37:07 PM
by the way, JPG and GIF files are very different from BMP's
i don't know, LoadImage might support one or both (i doubt it)
if so, it will load the image as a bitmap, though
it always returns a handle to a bitmap
Right. I normally use GdipCreateBitmapFromStream, and it doesn't care what format the buffer provides. So GetObject works fine with JPG, PNG & friends.
thanks, thats what I was looking for, so I can start to port some java and load small jpgs
and after I get it working improve speed
AW27, so agora descobri que voce e Portugues! Maravilha saber.
I confess to being very rusty with bitmaps but I am getting a weird result.
invoke GetObject,hBitmap,SIZEOF BITMAP, ADDR bmp
invoke MessageBox,hWnd,LastError$(),"LastError",MB_OK
mov ecx, bmp.bmWidth
mov edx, bmp.bmHeight
invoke MessageBox,hWnd,str$(rcx),"Width",MB_OK
invoke MessageBox,hWnd,str$(rdx),"Height",MB_OK
The width is correct but the height is wrong. The bitmap is 384 wide and 32 high but the results I am getting are respectively 384 and 100.
LATER : It helped not to overwrite EDX with the 1st messagebox call. :P
Quote from: LordAdef on March 29, 2018, 11:46:36 AM
AW27, so agora descobri que voce e Portugues! Maravilha saber.
Eu tenho andado bastante ocupado e só agora li sua mensagem. :biggrin: