Узнать размер изображения Topic is solved
Узнать размер изображения
Как узнать размер изображения (Ширину и Высоту), если известен только путь к файлу?
Re: Узнать размер изображения
ahk V1 , откройте папку изображений и выберите несколько файлов изображений с помощью F3
Code: Select all
;- open image folder and select some picture-files user mikeyww
;- Как узнать размер изображения (Ширину и Высоту), если известен только путь к файлу?
;- откройте папку изображений и выберите несколько файлов изображений с помощью F3
;-------- saved at 星期日 十一月 2022-11-20 10:42 UTC --------------
;- Scan muliplte images to check dimensions against list.
;- https://www.autohotkey.com/boards/viewtopic.php?f=76&t=110694
;-
;w:=320,h:=240
ImagesGuiEscape:
Gui, Hide
#IfWinActive ahk_class CabinetWClass
;---------------------------------------
F3::
Gui, Images:New
Gui, Font, s10
Gui, Add, ListView, w600 r30, Width|Height|Name
For fileNum, file in sel := getSelected() {
ToolTip, % fileNum " / " sel.Count()
img := imgSize(file)
;If (img.w && (img.w != w || img.h != h))
{
SplitPath, file, fn
LV_Add("", img.w, img.h, fn)
}
}
ToolTip
LV_ModifyCol(3, 480), LV_ModifyCol(2, "50 Sort Integer Center"), LV_ModifyCol(1, "50 Sort Integer Center")
Gui, Show,, % "Images (" LV_GetCount() " of " sel.Count() ")"
Return
Guiclose:
Exitapp
;---------------------------------------
#IfWinActive
imgSize(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}
}
;------------
getSelected() { ; https://www.autohotkey.com/boards/viewtopic.php?style=17&t=60403#p255256 by teadrinker
hwnd := WinExist("A"), selection := []
WinGetClass, class
If (class ~= "(Cabinet|Explore)WClass")
For window in ComObjCreate("Shell.Application").Windows {
Try window.hwnd
Catch
Return
If (window.hwnd = hwnd)
For item in window.document.SelectedItems
selection.Push(item.Path)
}
Return selection
}
;------------
esc::exitapp
Re: Узнать размер изображения Topic is solved
Code: Select all
Gui, Add, Picture, x0 y0 hwndmypic vImage, cr.png
controlgetpos,,,width,height,,ahk_id %mypic%
MsgBox, %width%, %height%
Code: Select all
FileSelectFile, OutputVar, , %A_ScriptDir%\, Выбор картинку, Изображение (*.PNG; *.APNG; *.GIF; *.BMP)
GuiControl, , Image, *w0 *h0 %OutputVar%
GuiControlGet, Size, pos, CrosshairPath
MsgBox, %SizeW%, %SizeH%
Re: Узнать размер изображения
спасибо
вот еще 3 примера :
GUI PICTURE transparent :
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
}
;==================================
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") }
}
;============================================================================
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
;------------