Bilder Größe ändern

  • Hallo zusammen,

    ich habe eine Frage zu folgendem Script.

    Wie kann man alle Dateien in einem Ordner
    auf einmal resizen?

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $sInImage = FileOpenDialog("Bilder",@WindowsDir & "\", "Bilder (*.jpg)", 1 + 4 )
    $sOutImage = @ScriptDir & "\19_Resize.jpg"

    [/autoit] [autoit][/autoit] [autoit]

    $iH = InputBox("Bildhöhe", "Bitte geben Sie die Höhe ein.", "", "")
    $iW = InputBox("Bildbreite", "Bitte geben Sie die Breite ein.", "", "")

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    _ImageResize($sInImage, $sOutImage, $iW, $iH)
    If @error Then MsgBox(0,"",@error)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# =========================================================================================
    ; Name...........: _ImageResize
    ; Description....: Resize an image and optionally convert it to the format you want.
    ; Syntax.........: _ImageResize($sInImage, $sOutImage, $iW, $iH)
    ; Parameters ....: $sInImage - Full path to the image to resize / convert.
    ; In types: *.bmp, *.gif, *.ico, *.jpg, *.jpeg, *.png, *.tif, *.tiff
    ; $sOutImage - Full path where to save the resized / converted image.
    ; Out types: *.bmp, *.gif, *.jpg, *.jpeg, *.png, *.tif, *.tiff
    ; $iW - Width to resize image to.
    ; $iH - Height to resize image to.
    ; Return values .: Success - Return 1 and @error 0
    ; Failure - Return 0 and @error 1~5
    ; @error 1 = In File does not exist
    ; @error 2 = In File format not supported
    ; @error 3 = Out File path does not exist
    ; @error 4 = Out file format not supported
    ; @error 5 = Resize Width or Height not an integer
    ; Author ........: smashly
    ; ====================================================================================================
    Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
    Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"

    [/autoit] [autoit][/autoit] [autoit]

    If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
    $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
    If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile path, to use later on.
    $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
    If Not FileExists($sOP) Then Return SetError(3, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile name, to use later on.
    $sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile extension , to use for the encoder later on.
    $Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1)))
    If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; WinAPI to create blank bitmap at the width and height to put your resized image on.
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    ;Load the image you want to resize.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

    [/autoit] [autoit][/autoit] [autoit]

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    [/autoit] [autoit][/autoit] [autoit]

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
    Do
    $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    [/autoit] [autoit][/autoit] [autoit]

    ;Prefix the number to the begining of the output filename
    $sOutImage = $sOP & $i & "_" & $sOF

    [/autoit] [autoit][/autoit] [autoit]

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)

    [/autoit] [autoit][/autoit] [autoit]

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Return SetError(0, 0, 1)
    EndFunc ;==>_ImageResize

    [/autoit]


    Liebe Grüße
    Ilse ;)

  • Hallo Chesstiger,

    habe das mal probiert.
    Leider klappt es immer noch nicht!

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    #include <File.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $sInImage = FileOpenDialog("Bilder",@WindowsDir & "\", "Bilder (*.jpg)", 1 + 4 )
    ;~ $sOutImage = @ScriptDir & "\19_Resize.jpg"

    [/autoit] [autoit][/autoit] [autoit]

    DirCreate(@ScriptDir & "\Resized")
    Global $sInImage = FileSelectFolder("Select folder with pictures", "", 4) & "\"
    Global $outfolder = @ScriptDir & "\Resized"

    [/autoit] [autoit][/autoit] [autoit]

    $iW = InputBox("Bildbreite", "Bitte geben Sie die Breite ein.", "", "")
    $iH = InputBox("Bildhöhe", "Bitte geben Sie die Höhe ein.", "", "")

    [/autoit] [autoit][/autoit] [autoit]

    Global $aFiles = _FileListToArray($sInImage, "*.???", 0)
    For $i = 1 To $aFiles[0]
    If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then _ImageResize($sInImage & $aFiles[$i], $iw,$ih, $outfolder)
    ;MsgBox(0,"",$aFiles[$i])
    Next
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    ShellExecute($outfolder)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    _ImageResize($sInImage, $outfolder, $iW, $iH)
    If @error Then MsgBox(0,"",@error)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
    Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"

    [/autoit] [autoit][/autoit] [autoit]

    If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
    $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
    If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile path, to use later on.
    $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
    If Not FileExists($sOP) Then Return SetError(3, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile name, to use later on.
    $sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile extension , to use for the encoder later on.
    $Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1)))
    If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; WinAPI to create blank bitmap at the width and height to put your resized image on.
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    ;Load the image you want to resize.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

    [/autoit] [autoit][/autoit] [autoit]

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    [/autoit] [autoit][/autoit] [autoit]

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
    Do
    $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    [/autoit] [autoit][/autoit] [autoit]

    ;Prefix the number to the begining of the output filename
    $sOutImage = $sOP & $i & "_" & $sOF

    [/autoit] [autoit][/autoit] [autoit]

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)

    [/autoit] [autoit][/autoit] [autoit]

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Return SetError(0, 0, 1)
    EndFunc ;==>_ImageResize

    [/autoit]

    Bilder werden in Msgbox angezeigt
    aber es kommt eine Fehlermeldung!

    Liebe Grüße
    Ilse ;)

  • Probiers mal so (Zeile 18):

    [autoit]


    If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then _ImageResize($sInImage & "\" & $aFiles[$i], $iw,$ih, $outfolder)

    [/autoit]

    lg chess

  • @chess Er fügt den Backslash schon vorher ein.
    Ilse Das funktioniert nicht weil du die Funktion _ImageResize in der For Schleife aufrufst ohne jemals _GDIPlus_Startup aufgerufen zu haben... Außerdem gibt _FileListToArray auch Ordner zurück die dem angegebenen Muster entsprechen. Setz da mal den 3. Parameter auf 1 sonst kommt da in seltenen Fällen nur Blödsinn raus.

  • Hallo,

    geht aber immer noch nicht!

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    #include <File.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $sInImage = FileOpenDialog("Bilder",@WindowsDir & "\", "Bilder (*.jpg)", 1 + 4 )
    ;~ $sOutImage = @ScriptDir & "\19_Resize.jpg"

    [/autoit] [autoit][/autoit] [autoit]

    DirCreate(@ScriptDir & "\Resized")
    Global $sInImage = FileSelectFolder("Select folder with pictures", "", 4) & "\"
    Global $outfolder = @ScriptDir & "\Resized"

    [/autoit] [autoit][/autoit] [autoit]

    $iW = InputBox("Bildbreite", "Bitte geben Sie die Breite ein.", "", "")
    $iH = InputBox("Bildhöhe", "Bitte geben Sie die Höhe ein.", "", "")

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    Global $aFiles = _FileListToArray($sInImage, "*.???", 0)
    For $i = 1 To $aFiles[0]
    If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then _ImageResize($sInImage & $aFiles[$i], $iw,$ih, $outfolder)
    ;MsgBox(0,"",$aFiles[$i])
    Next
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    ShellExecute($outfolder)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    _ImageResize($sInImage, $outfolder, $iW, $iH)
    If @error Then MsgBox(0,"",@error)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ImageResize($sInImage, $sOutImage, $iW, $iH)
    Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"

    [/autoit] [autoit][/autoit] [autoit]

    If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
    $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
    If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile path, to use later on.
    $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
    If Not FileExists($sOP) Then Return SetError(3, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile name, to use later on.
    $sOF = StringTrimLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile extension , to use for the encoder later on.
    $Ext = StringUpper(StringTrimLeft($sOutImage, StringInStr($sOutImage, ".", 0, -1)))
    If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; WinAPI to create blank bitmap at the width and height to put your resized image on.
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    ;Load the image you want to resize.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

    [/autoit] [autoit][/autoit] [autoit]

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    [/autoit] [autoit][/autoit] [autoit]

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
    Do
    $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    [/autoit] [autoit][/autoit] [autoit]

    ;Prefix the number to the begining of the output filename
    $sOutImage = $sOP & $i & "_" & $sOF

    [/autoit] [autoit][/autoit] [autoit]

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)

    [/autoit] [autoit][/autoit] [autoit]

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Return SetError(0, 0, 1)
    EndFunc ;==>_ImageResize

    [/autoit]

    Ich habe _GDIPlus_Startup() Zeile 16 gestartet und später wieder geschlossen.
    Es kommt die Msgbox 2
    und der Zielordner ist leer!

    Mit nur einer Datei (Post 1) geht das Script!

    ;) Grüße Ilse

  • chesstiger
    Syntaxproblem, aber wieso?
    _ImageResize($sInImage,$outfolder,$iW,$iH)


    name22
    mit läuft einmal, meinte ich das allererste Script
    ohne FileListToArray....
    GDIPlus_Shutdown ist nun draußen...

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    #include <File.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $sInImage = FileOpenDialog("Bilder",@WindowsDir & "\", "Bilder (*.jpg)", 1 + 4 )
    ;~ $outfolder = @ScriptDir & "\19_Resize.jpg"

    [/autoit] [autoit][/autoit] [autoit]

    DirCreate(@ScriptDir & "\Resized")
    Global $sInImage = FileSelectFolder("Select folder with pictures", "", 4) & "\"
    Global $outfolder = @ScriptDir & "\Resized"

    [/autoit] [autoit][/autoit] [autoit]

    $iW = InputBox("Bildbreite", "Bitte geben Sie die Breite ein.", "", "")
    $iH = InputBox("Bildhöhe", "Bitte geben Sie die Höhe ein.", "", "")

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    Global $aFiles = _FileListToArray($sInImage, "*.???", 0)
    For $i = 1 To $aFiles[0]
    If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.jpg|.*\.bmp", 0) Then _ImageResize($sInImage & $aFiles[$i], $iw,$ih, $outfolder)
    ;MsgBox(0,"",$aFiles[$i])
    Next

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    ShellExecute($outfolder)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    _ImageResize($sInImage,$outfolder,$iW,$iH)
    If @error Then MsgBox(0,"Fehler",@error)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ImageResize($sInImage, $outfolder, $iW, $iH)
    Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"

    [/autoit] [autoit][/autoit] [autoit]

    If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
    $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
    If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile path, to use later on.
    $sOP = StringLeft($outfolder, StringInStr($outfolder, "\", 0, -1))
    If Not FileExists($sOP) Then Return SetError(3, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile name, to use later on.
    $sOF = StringTrimLeft($outfolder, StringInStr($outfolder, "\", 0, -1))

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile extension , to use for the encoder later on.
    $Ext = StringUpper(StringTrimLeft($outfolder, StringInStr($outfolder, ".", 0, -1)))
    If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; WinAPI to create blank bitmap at the width and height to put your resized image on.
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    ;Load the image you want to resize.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

    [/autoit] [autoit][/autoit] [autoit]

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    [/autoit] [autoit][/autoit] [autoit]

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
    Do
    $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    [/autoit] [autoit][/autoit] [autoit]

    ;Prefix the number to the begining of the output filename
    $outfolder = $sOP & $i & "_" & $sOF

    [/autoit] [autoit][/autoit] [autoit]

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $outfolder, $CLSID)

    [/autoit] [autoit][/autoit] [autoit]

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBitmap)
    ;_GDIPlus_Shutdown()
    Return SetError(0, 0, 1)
    EndFunc ;==>_ImageResize

    [/autoit]

    aber es läuft trotzdem nicht!


    Liebe Grüße
    Ilse ;)

  • übergib doch mal den Dateinamen zum Speichern, dann geht das auch:

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    #include <File.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $sInImage = FileOpenDialog("Bilder",@WindowsDir & "\", "Bilder (*.jpg)", 1 + 4 )
    ;~ $outfolder = @ScriptDir & "\19_Resize.jpg"

    [/autoit] [autoit][/autoit] [autoit]

    DirCreate(@ScriptDir & "\Resized")
    Global $sInImage = FileSelectFolder("Select folder with pictures", "", 4, @ScriptDir)
    Global $outfolder = @ScriptDir & "\Resized"

    [/autoit] [autoit][/autoit] [autoit]

    $iW = InputBox("Bildbreite", "Bitte geben Sie die Breite ein.", "", "")
    $iH = InputBox("Bildhöhe", "Bitte geben Sie die Höhe ein.", "", "")

    [/autoit] [autoit][/autoit] [autoit]

    Global $aFiles = _FileListToArray($sInImage, "*.???", 0)
    For $i = 1 To $aFiles[0]
    If StringRegExp($aFiles[$i], "(?i).*\.png|.*\.JPG|.*\.bmp", 0) Then _ImageResize($sInImage & "\" & $aFiles[$i], $outfolder& "\" & $aFiles[$i], $iw,$ih)
    ;MsgBox(0,"",$sInImage & "\" & $aFiles[$i])
    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ShellExecute($outfolder)

    [/autoit] [autoit][/autoit] [autoit]

    Func _ImageResize($sInImage, $outfolder, $iW, $iH)
    Local $sOP, $sOF, $sInExt, $Ext, $hBitmap, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
    Local $sType = "BMP|GIF|ICO|JPG|JPEG|PNG|TIF|TIFF"

    [/autoit] [autoit][/autoit] [autoit]

    If Not FileExists($sInImage) Then Return SetError(1, 0, 0)
    $sInExt = StringUpper(StringTrimLeft($sInImage, StringInStr($sInImage, ".", 0, -1)))
    If Not StringRegExp($sInExt, "\A(" & $sType & ")\z", 0) Then Return SetError(2, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile path, to use later on.
    $sOP = StringLeft($outfolder, StringInStr($outfolder, "\", 0, -1))
    If Not FileExists($sOP) Then Return SetError(3, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile name, to use later on.
    $sOF = StringTrimLeft($outfolder, StringInStr($outfolder, "\", 0, -1))

    [/autoit] [autoit][/autoit] [autoit]

    ;OutFile extension , to use for the encoder later on.
    $Ext = StringUpper(StringTrimLeft($outfolder, StringInStr($outfolder, ".", 0, -1)))
    If Not StringRegExp($Ext, "\A(" & $sType & ")\z", 0) Or $Ext = "ICO" Then Return SetError(4, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    If Not IsInt($iW) And Not IsInt($iH) Then Return SetError(5, 0, 0)

    [/autoit] [autoit][/autoit] [autoit]

    ;Start GDIPlus
    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    ; WinAPI to create blank bitmap at the width and height to put your resized image on.
    $hBitmap = _WinAPI_CreateBitmap($iW, $iH, 1, 32)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the handle of blank bitmap you created above as an image
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    ;Load the image you want to resize.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the graphic context of the blank bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)

    [/autoit] [autoit][/autoit] [autoit]

    ;Draw the loaded image onto the blank bitmap at the size you want
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)

    [/autoit] [autoit][/autoit] [autoit]

    ;Get the encoder of to save the resized image in the format you want.
    $CLSID = _GDIPlus_EncodersGetCLSID($Ext)

    [/autoit] [autoit][/autoit] [autoit]

    ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
    Do
    $i += 1
    Until (Not FileExists($sOP & $i & "_" & $sOF))

    [/autoit] [autoit][/autoit] [autoit]

    ;Prefix the number to the begining of the output filename
    $outfolder = $sOP & $i & "_" & $sOF

    [/autoit] [autoit][/autoit] [autoit]

    _setres($hImage1); DPI setzen (Vorgabe 180)

    [/autoit] [autoit][/autoit] [autoit]

    ;Save the new resized image.
    _GDIPlus_ImageSaveToFileEx($hImage1, $outfolder, $CLSID)

    [/autoit] [autoit][/autoit] [autoit]

    ;Clean up and shutdown GDIPlus.
    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBitmap)
    _GDIPlus_Shutdown()
    Return SetError(0, 0, 1)
    EndFunc ;==>_ImageResize

    [/autoit] [autoit][/autoit] [autoit]

    Func _setres($hBitmap, $nDpiX= 180, $nDPIY = 180)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapSetResolution", "hwnd", $hBitmap, "float", $nDpiX, "float", $nDPIY)
    Return $aResult[0] = 0
    EndFunc

    [/autoit]

    Einmal editiert, zuletzt von Torni (20. September 2012 um 13:06)