Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Read the image size (solved)


  • Please log in to reply
11 replies to this topic
Albireo
  • Members
  • 558 posts
  • Last active: Dec 13 2019 02:02 PM
  • Joined: 01 Feb 2006
Hello!

I want to know / to read the size of an image (x-pixels, y-pixels)
Is it possible with AHK?

//Jan

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Yes!

GDI+ Standard Library

Albireo
  • Members
  • 558 posts
  • Last active: Dec 13 2019 02:02 PM
  • Joined: 01 Feb 2006
Thank´s for the answer! :D

But I can´t se how :(
You can create many images in many ways with this "script"

But if I have an image I want to know the x,y-size (in pixels)
(Before I want to process the image)

//Jan

  • Guests
  • Last active:
  • Joined: --
imagefile=c:\image.png



GDIPToken := Gdip_Startup()                                     

pBM := Gdip_CreateBitmapFromFile( imagefile )                 

W:= Gdip_GetImageWidth( pBM )

H:= Gdip_GetImageHeight( pBM )   

Gdip_DisposeImage( pBM )                                          

Gdip_Shutdown( GDIPToken )                                        



MsgBox, width=%W%  height=%H%



#Include Gdip.ahk


Albireo
  • Members
  • 558 posts
  • Last active: Dec 13 2019 02:02 PM
  • Joined: 01 Feb 2006

imagefile=c:\image.png

GDIPToken := Gdip_Startup()                                     
pBM := Gdip_CreateBitmapFromFile( imagefile )                 
W:= Gdip_GetImageWidth( pBM )
H:= Gdip_GetImageHeight( pBM )   
Gdip_DisposeImage( pBM )                                          
Gdip_Shutdown( GDIPToken )                                        

MsgBox, width=%W%  height=%H%

#Include Gdip.ahk


Jepp! It works!
(I haven' t see this :-)

Thank you!

//Jan

Albireo
  • Members
  • 558 posts
  • Last active: Dec 13 2019 02:02 PM
  • Joined: 01 Feb 2006

imagefile=c:\image.png

GDIPToken := Gdip_Startup()                                     
pBM := Gdip_CreateBitmapFromFile( imagefile )                 
W:= Gdip_GetImageWidth( pBM )
H:= Gdip_GetImageHeight( pBM )   
Gdip_DisposeImage( pBM )                                          
Gdip_Shutdown( GDIPToken )                                        

MsgBox, width=%W%  height=%H%

#Include Gdip.ahk
.....


Can I have this "code" in an other Function?
(It doesn't work for me :( )

//Jan

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Can I have this "code" in an other Function?


Can you please further define "other Function" ? .. or post a part of your code that shows your usage of the given code.

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
Here's another way to get the size of an image. It doesn't depend on GDI+
The GUI number 99 is arbitrary, just don't want to interfere with an existing GUI.

imagefile=c:\image.png 

guinum=99

gui, %guinum%:add, picture, vmypic, %imagefile%
GuiControlGet, mypic, %guinum%:Pos
gui, %guinum%:destroy

;MsgBox The X coordinate is %mypicX%. The Y coordinate is %mypicY%. 

MsgBox The width is %mypicW%. The height is %mypicH%.

return


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear leef_me: That would not work if the image dimensions are larger than A_ScreenWidth / A_ScreenHeight. :)

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

Can I have this "code" in an other Function?

Do you need something like this?
;Example:
MsgBox % GetImageSize("C:\image.png")

;===Functions===
#Include Gdip.ahk				; by Tic. Location: http://www.autohotkey.com/forum/topic32238.html
GetImageSize(ImageFullPath) {
	GDIPToken := Gdip_Startup()                             
	pBM := Gdip_CreateBitmapFromFile( ImageFullPath )                 
	W:= Gdip_GetImageWidth( pBM ), H:= Gdip_GetImageHeight( pBM )   
	Gdip_DisposeImage( pBM ), Gdip_Shutdown( GDIPToken )
	return w "x" h
}


Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009

Dear leef_me: That would not work if the image dimensions are larger than A_ScreenWidth / A_ScreenHeight. :)

Dear SKAN, your statement is incorrect.
I just tested the script with an oversize image 3125 x 1768 and it works. :wink:

I used such a large value in case my (3) monitors 1024 x 768 might allow for bigger images.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Dear SKAN, your statement is incorrect.


Jeez!. I did not look into your code properly. Last time I tried something like that, I was ascertaining the GUI size instead of control's size. Thank you. Your snippet is a treat.