Hi clamicun,
The ReadFileToMem function has no stack frame and this is why it looks complicated. JoeBr's suggestion is nice as you can use GDI+ to get the required information :
include GetImageSize.inc
.data
msg1 db 'Usage : GetImageSize.exe imagefile.ext',13,10,0
msg2 db 'Width = %u',13,10
db 'Height = %u',0
.data?
hBitmap dd ?
BmpImage dd ?
token dd ?
ImgWidth dd ?
ImgHeight dd ?
buffer1 db 1024 dup(?)
buffer2 db 32 dup(?)
StartupInfo GdiplusStartupInput <?>
.code
start:
call main
invoke ExitProcess,0
main PROC uses esi
mov esi,OFFSET buffer1
invoke ParseCmdLineW,esi
cmp eax,1+1
je @f
invoke StdOut,ADDR msg1
ret
@@:
mov eax,OFFSET StartupInfo
mov GdiplusStartupInput.GdiplusVersion[eax],1
invoke GdiplusStartup,ADDR token,ADDR StartupInfo,0
invoke GdipCreateBitmapFromFile,DWORD PTR [esi+4],\
ADDR BmpImage
invoke GdipGetImageWidth,BmpImage,ADDR ImgWidth
invoke GdipGetImageHeight,BmpImage,ADDR ImgHeight
invoke wsprintf,ADDR buffer2,ADDR msg2,ImgWidth,\
ImgHeight
invoke StdOut,ADDR buffer2
invoke GdipDisposeImage,BmpImage
invoke GdiplusShutdown,token
ret
main ENDP
END start
GetImageSize.exe Test.JPG
Width = 116
Height = 80
The tool can read information from .gif and .tif images. The advantage of the GDI+ method is that you don't need to know anything about the image format.
Hi JoeBr,
Thanks for your idea and welcome to the forum :t