Post by garry » 09 Jan 2024, 11:19
спасибо
Code: Select all
Gui,Add,Picture,x0 y0 hwndmypic,C:\test.jpg
controlgetpos,,,width,height,,ahk_id %mypic%
MsgBox,W=%width%`nH=%height%
exitapp
Code: Select all
FileSelectFile, OutputVar, , %A_ScriptDir%\, Выбор картинку, Изображение (*.PNG; *.APNG; *.GIF; *.BMP;*.JPG)
Gui,Add,Picture,x10 y15 hwndmypic vImage,%OutputVar%
Gui,show,x200 y250,TEST
sleep,500
GuiControlGet,aa,pos,static1
MsgBox,X=%aaX%`nY=%aaY%`nW=%aaW%`nH=%aaH%
return
Guiclose:
exitapp
Code: Select all
xc:="C:\test.jpg"
imgSize(xc,imgw,imgh)
msgbox,W=%imgw%`nH=%imgh%
exitapp
;---------------------
imgSize(img, ByRef width , ByRef height) { ; Get image's dimensions
If FileExist(img) {
GUI, Add, Picture, hwndpic, %img%
ControlGetPos,,, width, height,, ahk_id %pic%
Gui, Destroy
} Else height := width := 0
}
;==================================
вот еще 3 примера :
Code: Select all
;- Detect invalid filetype doing GUI ADD PICTURE / 3 examples
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=109286
P1:="c:\test.jpg"
;---------- 1st ----------------------
aa1:= imgSize1(P1).w,bb1:= imgSize1(P1).h
msgbox,Function-1`nW=%aa1%`nH=%bb1%
;---------- 2nd -----------------------
imgSize2(P1,imgw,imgh)
aa2:=imgw,bb2:=imgh
msgbox,Function-2`nW=%aa2%`nH=%bb2%
;---------- 3thd -----------------------
size := GetImageSize(P1)
aa3:=size.W , bb3:=size.H
msgbox,Function-3`nW=%aa3%`nH=%bb3%
return
;---------------------------------------
;-1st function
;----------------------
imgSize1(img) { ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81665
; Returns an array indicating the image's width (w) and height (h), obtained from the file's properties
SplitPath, img, fn, dir
objShell := ComObjCreate("Shell.Application")
objFolder := objShell.NameSpace(dir), objFolderItem := objFolder.ParseName(fn)
scale := StrSplit(RegExReplace(objFolder.GetDetailsOf(objFolderItem, 31), ".(.+).", "$1"), " x ")
Return {w: scale.1, h: scale.2}
}
;---------------------
;- 2nd function
;---------------------
imgSize2(img, ByRef width , ByRef height) { ;-https://www.autohotkey.com/boards/viewtopic.php?p=355790#p355790 mikeyww
If FileExist(img) {
GUI, Add, Picture, hwndpic, %img%
ControlGetPos,,, width, height,, ahk_id %pic%
Gui, Destroy
} Else height := width := 0
}
;----------------------
;- 3thd function
;----------------------
GetImageSize(imageFilePath) { ;- https://www.autohotkey.com/boards/viewtopic.php?p=355794#p355794 teadrinker
if !hBitmap := LoadPicture(imageFilePath, "GDI+")
throw "Failed to load the image"
VarSetCapacity(BITMAP, size := 4*4 + A_PtrSize*2, 0)
DllCall("GetObject", "Ptr", hBitmap, "Int", size, "Ptr", &BITMAP)
DllCall("DeleteObject", "Ptr", hBitmap)
Return { W: NumGet(BITMAP, 4, "UInt"), H: NumGet(BITMAP, 8, "UInt") }
}
;============================================================================
GUI PICTURE transparent :
Code: Select all
#warn
#NoEnv
setworkingdir,%a_scriptdir%
Scriptname=PictureSize_EDIT_Transparent
Gui,2:default
Gui,2: -dpiscale
Gui,2:Color,Black,
Gui,2: Font, s18 cBlack bold,Lucida Console
P1=C:\test.jpg
;- pw is the width
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100,px:=(wa*1)/xx,py:=(ha*1.5)/xx,pw:=(wa*50)/xx,adw:=(wa*2)/xx
Gui,2: Add, Picture,x%px% y%py% w%pw% h-1 vPicture1,%p1%
GuiControlGet, Pic, Pos, Picture1
eh:=((pw*PicH)/PicW)
gh:=((pw*PicH)/PicW) +adw
gw:=pw+adw
Gui,2: Add, Edit ,x%px% y%py% w%pw% h%eh% -hscroll -vscroll Hwnduid
WinSet, Transparent, 150, ahk_id %uid%
Gui,2: Show, x0 y0 w%gw% h%gh% ,%Scriptname%
return
;------------
2Guiclose:
exitapp
;------------
спасибо
[code]
Gui,Add,Picture,x0 y0 hwndmypic,C:\test.jpg
controlgetpos,,,width,height,,ahk_id %mypic%
MsgBox,W=%width%`nH=%height%
exitapp
[/code]
[code]
FileSelectFile, OutputVar, , %A_ScriptDir%\, Выбор картинку, Изображение (*.PNG; *.APNG; *.GIF; *.BMP;*.JPG)
Gui,Add,Picture,x10 y15 hwndmypic vImage,%OutputVar%
Gui,show,x200 y250,TEST
sleep,500
GuiControlGet,aa,pos,static1
MsgBox,X=%aaX%`nY=%aaY%`nW=%aaW%`nH=%aaH%
return
Guiclose:
exitapp
[/code]
[code]xc:="C:\test.jpg"
imgSize(xc,imgw,imgh)
msgbox,W=%imgw%`nH=%imgh%
exitapp
;---------------------
imgSize(img, ByRef width , ByRef height) { ; Get image's dimensions
If FileExist(img) {
GUI, Add, Picture, hwndpic, %img%
ControlGetPos,,, width, height,, ahk_id %pic%
Gui, Destroy
} Else height := width := 0
}
;==================================
[/code]
вот еще 3 примера :
[code];- Detect invalid filetype doing GUI ADD PICTURE / 3 examples
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=109286
P1:="c:\test.jpg"
;---------- 1st ----------------------
aa1:= imgSize1(P1).w,bb1:= imgSize1(P1).h
msgbox,Function-1`nW=%aa1%`nH=%bb1%
;---------- 2nd -----------------------
imgSize2(P1,imgw,imgh)
aa2:=imgw,bb2:=imgh
msgbox,Function-2`nW=%aa2%`nH=%bb2%
;---------- 3thd -----------------------
size := GetImageSize(P1)
aa3:=size.W , bb3:=size.H
msgbox,Function-3`nW=%aa3%`nH=%bb3%
return
;---------------------------------------
;-1st function
;----------------------
imgSize1(img) { ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=81665
; Returns an array indicating the image's width (w) and height (h), obtained from the file's properties
SplitPath, img, fn, dir
objShell := ComObjCreate("Shell.Application")
objFolder := objShell.NameSpace(dir), objFolderItem := objFolder.ParseName(fn)
scale := StrSplit(RegExReplace(objFolder.GetDetailsOf(objFolderItem, 31), ".(.+).", "$1"), " x ")
Return {w: scale.1, h: scale.2}
}
;---------------------
;- 2nd function
;---------------------
imgSize2(img, ByRef width , ByRef height) { ;-https://www.autohotkey.com/boards/viewtopic.php?p=355790#p355790 mikeyww
If FileExist(img) {
GUI, Add, Picture, hwndpic, %img%
ControlGetPos,,, width, height,, ahk_id %pic%
Gui, Destroy
} Else height := width := 0
}
;----------------------
;- 3thd function
;----------------------
GetImageSize(imageFilePath) { ;- https://www.autohotkey.com/boards/viewtopic.php?p=355794#p355794 teadrinker
if !hBitmap := LoadPicture(imageFilePath, "GDI+")
throw "Failed to load the image"
VarSetCapacity(BITMAP, size := 4*4 + A_PtrSize*2, 0)
DllCall("GetObject", "Ptr", hBitmap, "Int", size, "Ptr", &BITMAP)
DllCall("DeleteObject", "Ptr", hBitmap)
Return { W: NumGet(BITMAP, 4, "UInt"), H: NumGet(BITMAP, 8, "UInt") }
}
;============================================================================
[/code]
GUI PICTURE transparent :
[code]#warn
#NoEnv
setworkingdir,%a_scriptdir%
Scriptname=PictureSize_EDIT_Transparent
Gui,2:default
Gui,2: -dpiscale
Gui,2:Color,Black,
Gui,2: Font, s18 cBlack bold,Lucida Console
P1=C:\test.jpg
;- pw is the width
wa:=A_screenwidth,ha:=A_screenHeight,xx:=100,px:=(wa*1)/xx,py:=(ha*1.5)/xx,pw:=(wa*50)/xx,adw:=(wa*2)/xx
Gui,2: Add, Picture,x%px% y%py% w%pw% h-1 vPicture1,%p1%
GuiControlGet, Pic, Pos, Picture1
eh:=((pw*PicH)/PicW)
gh:=((pw*PicH)/PicW) +adw
gw:=pw+adw
Gui,2: Add, Edit ,x%px% y%py% w%pw% h%eh% -hscroll -vscroll Hwnduid
WinSet, Transparent, 150, ahk_id %uid%
Gui,2: Show, x0 y0 w%gw% h%gh% ,%Scriptname%
return
;------------
2Guiclose:
exitapp
;------------
[/code]