Since I do not know how to scale an image with AHK GUI (I think it's impossible), I need to know the width and height of the image to be displayed to get structure on the entire GUI.
One way to get the size is to use IrfanView - Command line
Another way is to use gdip_all
Maybe there are better ways to do this on?
My wish is to create an object (selLogo) that contains information about the image. (eg. selLogo.name, selLogo.width, selLogo.height ...)
Tried to write a program below, but failed (in a way)
(selLogo is changed after the function call getImageSize(selLogo.name) and the selLogo.name is gone!)
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#include gdip_all.ahk ; If it is not in your lib http://www.autohotkey.com/forum/topic32238.html
selLogo := []
FileSelectFile Logo, 3, C:\Users...\images, Select a imagefile, Images (*.jpg)
selLogo.name := Logo
selLogo := getImageSize(selLogo.name)
MsgBox ,, %A_ScriptName% - Row %A_LineNumber%, % "- " selLogo.Count() "`n- " selLogo.name "`n`nheight .: " selLogo.height "`nwidth .: " selLogo.width
ExitApp
getImageSize(imageFile)
{ ; https://autohotkey.com/board/topic/61076-get-image-height-property-from-file-property-details/
; lib .: gdip_all.ahk
aImage := []
If !pToken := Gdip_Startup()
{ MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
pBitmap := Gdip_CreateBitmapFromFile(imageFile)
Gdip_GetDimensions(pBitmap, width, height)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
aImage.width := width
aImage.height := height
Return % aImage
}