Bild laden und die größe in 2 variablen speicher Breite und Höhe

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Bild laden und die größe in 2 variablen speicher Breite und Höhe

Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe

Post by haichen » 25 Dec 2019, 11:29

Nicht ganz so ein Totschläger wie SKANs andere Funktion.
Und schöne :xmas: an alle!

Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe

Post by just me » 25 Dec 2019, 11:20

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:

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)
}
:xmas:

Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe

Post by gregster » 25 Dec 2019, 11:15

haichen wrote:
25 Dec 2019, 11:12
Hmm, der Code sieht aber unschön aus. NACH dem Speichern sind alle Einrückungen weg.
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

Post by haichen » 25 Dec 2019, 11:12

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

Post by haichen » 25 Dec 2019, 11:05

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:

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  

} 

Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe

Post by nacken012 » 24 Dec 2019, 20:45

Vielen Dank, das klappt perfekt :-)

Re: Bild laden und die größe in 2 variablen speicher Breite und Höhe

Post by KHA » 24 Dec 2019, 14:05

Eine Möglichkeit wäre über 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

Bild laden und die größe in 2 variablen speicher Breite und Höhe

Post by nacken012 » 24 Dec 2019, 10:49

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

Top