zoplonix
zoplonix

Reputation: 1072

Resize Picture and Keep Aspect Ratio in Autohotkey GUI

Is it possible to have an image be 100% of the window width and keep it's aspect ratio while resizing an AutoHotKey GUI?

I have a simple GUI as follows:

Gui +Resize
Gui, Add, Picture, w440 h-1 vProductImage, default.png
Gui, Show, , MyApp

The closest thing I have been able to come to is Anchor.ahk http://www.autohotkey.com/board/topic/4105-control-anchoring-v4-for-resizing-windows/

Using it, I can have the image resized when the window is resized but it doesn't keep it's aspect ratio and gets deformed

Does anyone know how I can do this?

Upvotes: 1

Views: 2640

Answers (1)

zoplonix
zoplonix

Reputation: 1072

Closest thing I could come up with:

Assuming the picture is 440x350, is 85 pixels from the top of the app window (left:0)

GuiSize:
if(A_GuiWidth < A_GuiHeight)
{
    GuiControl, MoveDraw, ProductImage, % "w" . (A_GuiWidth - 20) . " h" . (350/440) * (A_GuiWidth - 20)
}
else
{
    GuiControl, MoveDraw, ProductImage, % "w" . (440/350) * (A_GuiHeight - 85) . " h" . (A_GuiHeight - 85)
}
return

(the 20 is for window padding)

Upvotes: 1

Related Questions