AutoPicWH() - rescale and reload pictures

Post your working scripts, libraries and tools for AHK v1.1 and older
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

AutoPicWH() - rescale and reload pictures

12 Feb 2015, 11:26

This function only makes sense in combination with AutoXYZ.
You load the picture into your picture control outside of GuiSize by specifying vPic, Filname and the dominant dimension in the AutoPicWH(vPic, Filename, DominantDim) call.
In the GuiSize subroutine you call after the AutoXYZ() function calls once AutoPicWH().
The picture controls still have to be rezised with AutoXYZ(). This function only reloads the picture to increase picture quality when the control gets larger and ensures that the aspect ration is maintained and the picture stays within the original boundaries.

Code: Select all

AutoPicWH(vPic:="", Filename:="", DominantDim:="w"){
  static cInfo := {}
  ctrlID := A_Gui ":" vPic
  If (vPic = "") {
    For ctrlID, Data in cInfo {
      c := StrSplit(ctrlID, ":")
      GuiControlGet, i, % c.1 ":Pos", % c.2
      DominantDim := iw/ih < Data.a ? "w" : "h"
      GuiControl, % c.1 ":" , % c.2, % "*" DominantDim i%DominantDim% " *" (DominantDim="w"?"h":"w") "-1 " Data.f
    }
  }Else {
    GuiControlGet, i, %A_Gui%:Pos, %vPic%
    GuiControl, % A_Gui ":", % vPic , % "*" DominantDim i%DominantDim% " *" (DominantDim="w"?"h":"w") "-1 " FileName
    GuiControlGet, j, %A_Gui%:Pos, %vPic%
    cInfo[ctrlID] := {f:Filename, d:DominantDim, a:jW/jH}
  }
}
Known shortcoming: It's not possible to load a different file into the picture control. Since I do not need it at this time, I leave it for now to the community to figure out a way or even to show me an easier path then the one I took.
ciao
toralf

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 147 guests