GuiControl,,,HBITMAP:%hBM% and Gui, Add, Picture,, HBITMAP:%hBM% should not stretch-to-fit the image when SS_CENTERIMAGE flag is in effect
If a 1000x1000 image is applied to a w100 h100 picture control then only the center 100² pixels should be displayed...
This is the default behaviour SS_CENTERIMAGE flag is in effect.
This wasn't important when Filename was used to create a picture control. Now that we have
HBITMAP: parameter as well as a LoadPicture() function, it is possible to find the dimensions
and scale down the image to perfectly fit the picture control.
I will post a working demo and link it here.
Meanwhile, here are snippets to show the problem.
Code: Select all
#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir %A_ScriptDir%
IfNotExist, logo.png
URLDownloadToFile, https://autohotkey.com/assets/images/ahk-logo-no-text241x78-180.png, logo.png
hBM := LoadPicture( "logo.png" )
OPTIONS := ( SS_CENTERIMAGE := 0x200 )
Gui, Add, Picture, w400 h200 %OPTIONS% vPicture
GuiControl,, Picture, HBITMAP:%hbm%
Gui, Show,, SS_CENTERIMAGE is ignored by GuiControl
Return
GuiClose:
GuiEscape:
ExitApp
Code: Select all
#NoEnv
#Warn
#SingleInstance, Force
SetWorkingDir %A_ScriptDir%
IfNotExist, logo.png
URLDownloadToFile, https://autohotkey.com/assets/images/ahk-logo-no-text241x78-180.png, logo.png
hBM := LoadPicture( "logo.png" )
OPTIONS := ( SS_BITMAP := 0xE ) | ( SS_CENTERIMAGE := 0x200 )
Gui, Add, Picture, w400 h200 %OPTIONS% vPicture hwndhwndPic Border
oBM := DllCall( "SendMessage", "Ptr",hwndPic, "UInt",0x172, "Ptr",0, "Ptr",hBM ) ; STM_SETIMAGE = 0x172
Gui, Show,, Workaround with STM_SETIMAGE
Return
GuiClose:
GuiEscape:
ExitApp