[solved] Get image dimensions from JPEG or PNG file

Get help with using AutoHotkey and its commands and hotkeys
User avatar
Micromegas
Posts: 220
Joined: 28 Apr 2015, 23:02
Location: Germany

[solved] Get image dimensions from JPEG or PNG file

08 Mar 2016, 22:41

I'm wondering if there is any code available to retrieve the dimensions of a JPEG or PNG file. Something like this exists for other languages, e.g. VB.NET at http://www.freevbcode.com/ShowCode.asp?ID=9102. I could port that to AHK, but it has over 300 LOC, which is an effort I would like to avoid. (I'm aware that the VB.NET code does a lot more than what I need, but it also takes work to pare it down.)
Last edited by Micromegas on 09 Mar 2016, 21:11, edited 1 time in total.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Get image dimensions from JPEG or PNG file

08 Mar 2016, 23:04

There seems to be two methods in the following thread, one using a GUI and another using Gdip.ahk:
https://autohotkey.com/board/topic/5530 ... ze-solved/
Note regarding the Gui example: Gui, New has been added in the meantime, so you don't need to create an arbitrarily numbered gui, you can create an unnumbered gui.

A function I wrote, FileGetProperties, would do the trick too. Although it's probably slower.
User avatar
Micromegas
Posts: 220
Joined: 28 Apr 2015, 23:02
Location: Germany

Re: Get image dimensions from JPEG or PNG file

08 Mar 2016, 23:44

kon wrote:A function I wrote, FileGetProperties, would do the trick too. Although it's probably slower.
Great, thanks! I just tried FileGetProperties and I love it - it's something I can use for other purposes too, and it's fast enough, at roughly 20ms execution time.
tic
Posts: 92
Joined: 03 Nov 2014, 03:10

Re: [solved] Get image dimensions from JPEG or PNG file

10 Mar 2016, 12:57

Code: Select all

pToken := Gdip_StartUp()
pBitmap := Gdip_CreateBitmapFromFile("c:\myImage.jpg")
Gdip_GetImageDimensions(pBitmap, w, h)
Gdip_DisposeImage(pBitmap)
Gdip_ShutDown(pToken)
MsgBox, % "Width: " w " Height: " h

Return to “Ask For Help”

Who is online

Users browsing this forum: hasantr, mcl, mikeyww, skido, wineguy and 32 guests