Hallo, gibt es einen Befehl womit man 1 Bild laden kann und die Größe ich 2 Variablen speichern kann ?
Also nicht die Filegröße sondern die Pixel Maße Breite und Höhe
Bild laden und die größe in 2 variablen speicher Breite und Höhe
Moderator: jNizM
Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe
Eine Möglichkeit wäre über Gdip_All.ahk
Herunterladbar hier:
https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Gdip_All.ahk
Herunterladbar hier:
https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Gdip_All.ahk
Code: Select all
#Include, Gdip_All.ahk
pToken := Gdip_StartUp()
pBitmap := Gdip_CreateBitmapFromFile("pic.jpg")
Gdip_GetImageDimensions(pBitmap, w, h)
Gdip_DisposeImage(pBitmap)
Gdip_ShutDown(pToken)
MsgBox, % "Width: " w " Height: " h
Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe
Vielen Dank, das klappt perfekt
Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe
Ich dachte erst, es gibt bestimmt eine einfache Lösung, da man die Werte ja im Explorer in den Dateieigenschaften findet (Rechtsklick-Eigenschaften-Details-Breite/Höhe)
Aber scheint nicht so. Zwei Links habe ich gefunden:
FGP - FileGetProperties https://www.autohotkey.com/boards/viewtopic.php?t=3806 von Kon
Filexpro - File Extended Properties https://www.autohotkey.com/boards/viewtopic.php?t=59882 von SKAN
Hier habe ich mal das Ergebnis mit SKANs cooler Funktion ausgelesen:
Aber scheint nicht so. Zwei Links habe ich gefunden:
FGP - FileGetProperties https://www.autohotkey.com/boards/viewtopic.php?t=3806 von Kon
Filexpro - File Extended Properties https://www.autohotkey.com/boards/viewtopic.php?t=59882 von SKAN
Hier habe ich mal das Ergebnis mit SKANs cooler Funktion ausgelesen:
Code: Select all
obj:=Filexpro( "pic.jpg",, "System.Image.HorizontalSize", "System.Image.VerticalSize")
Breite:= obj["System.Image.HorizontalSize"]
Hoehe:= obj["System.Image.VerticalSize"]
msgbox % Breite " x " Hoehe
return
Filexpro( sFile := "", Kind := "", P* ) { ; v.90 By SKAN on D1CC @ goo.gl/jyXFo9
Local
Static xDetails
If ( sFile = "" )
{ ; Deinit static variable
xDetails := ""
Return
}
fex := {}, _FileExt := ""
Loop, Files, % RTrim(sfile,"\*/."), DF
{
If not FileExist( sFile:=A_LoopFileLongPath )
{
Return
}
SplitPath, sFile, _FileExt, _Dir, _Ext, _File, _Drv
If ( p[p.length()] = "xInfo" ) ; Last parameter is xInfo
{
p.Pop() ; Delete parameter
fex.SetCapacity(11) ; Make room for Extra info
fex["_Attrib"] := A_LoopFileAttrib
fex["_Dir"] := _Dir
fex["_Drv"] := _Drv
fex["_Ext"] := _Ext
fex["_File"] := _File
fex["_File.Ext"] := _FileExt
fex["_FilePath"] := sFile
fex["_FileSize"] := A_LoopFileSize
fex["_FileTimeA"] := A_LoopFileTimeAccessed
fex["_FileTimeC"] := A_LoopFileTimeCreated
fex["_FileTimeM"] := A_LoopFileTimeModified
}
Break
}
If Not ( _FileExt ) ; Filepath not resolved
{
Return
}
objShl := ComObjCreate("Shell.Application")
objDir := objShl.NameSpace(_Dir)
objItm := objDir.ParseName(_FileExt)
If ( VarSetCapacity(xDetails) = 0 ) ; Init static variable
{
i:=-1, xDetails:={}, xDetails.SetCapacity(309)
While ( i++ < 309 )
{
xDetails[ objDir.GetDetailsOf(0,i) ] := i
}
xDetails.Delete("")
}
If ( Kind and Kind <> objDir.GetDetailsOf(objItm,11) ) ; File isn't desired kind
{
Return
}
i:=0, nParams:=p.Count(), fex.SetCapacity(nParams + 11)
While ( i++ < nParams )
{
Prop := p[i]
If ( (Dot:=InStr(Prop,".")) and (Prop:=(Dot=1 ? "System":"") . Prop) )
{
fex[Prop] := objItm.ExtendedProperty(Prop)
Continue
}
If ( PropNum := xDetails[Prop] ) > -1
{
fex[Prop] := ObjDir.GetDetailsOf(objItm,PropNum)
Continue
}
}
fex.SetCapacity(-1)
Return fex
}
Last edited by haichen on 25 Dec 2019, 11:18, edited 1 time in total.
Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe
Hmm, der Code sieht aber unschön aus. NACH dem Speichern sind alle Einrückungen weg.
Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe
Nicht, wenn du für Code tatsächlich [code][/code]-Tags verwendest anstatt von [quote][/quote]-Tags
(das letztere keine Tabs respektieren, wie auch generall der Text in Posts, ist allerdings tatsächlich unschön)
Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe
Moin, ich war sicher, das Folgende schon gepostet zu haben:
Wenn Du GDI+ nicht sowieso brauchst, könnte diese ursprünglich von SKAN vorgestellte Lösung etwas 'schlanker' sein:
Wenn Du GDI+ nicht sowieso brauchst, könnte diese ursprünglich von SKAN vorgestellte Lösung etwas 'schlanker' sein:
Code: Select all
#NoEnv
ImageFile := A_ScriptDir . "\Roller 001.jpg"
S := A_TickCOunt
Result := GetImageDimensions(ImageFile, W, H)
T := A_TickCount - S
MsgBox, 0, Result: %Result%, W: %W% - H: %H% - T: %T%
ExitApp
GetImageDimensions(Imagefile, ByRef W, Byref H) {
W := H := 0
If (HBM := LoadPicture(ImageFile, "GDI+")) {
SizeOfBITMAP := 16 + (A_PtrSize * 2)
VarSetCapacity(BITMAP, SizeOfBITMAP, 0)
If DllCall("GetObject", "Ptr", HBM, "Int", SizeOfBITMAP, "Ptr", &BITMAP, "Int") {
W := NumGet(BITMAP, 4, "Int")
H := NumGet(BITMAP, 8, "Int")
}
DllCall("DeleteObject", "Ptr", HBM)
}
Return !!(W + H)
}
Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe
Nicht ganz so ein Totschläger wie SKANs andere Funktion.
Und schöne an alle!
Und schöne an alle!
Who is online
Users browsing this forum: No registered users and 60 guests