Naja, ich hatte ein wenig Langeweile und mich mal damit probiert.
Der Nachteil ist: Es funktioniert nicht!
Deswegen muss nochmal jemand drüber schauen, weil ich das Problem nicht kenne.
Das Konvertieren funktioniert natürlich, nur die Auflösung zu ändern nicht. Das Bild hat danach immer eine Größe von 631 Bytes und ist ein Pixel....
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GDIPlus.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Bild des Monats | Umbenenner (All to .jpg)", 431, 205)
GUISetBkColor(0xA0A0A4)
$Input1 = GUICtrlCreateInput("", 8, 24, 305, 21)
$hBtn_Search = GUICtrlCreateButton("Durchsuchen", 320, 22, 97, 25)
$Label1 = GUICtrlCreateLabel("Bild wählen", 8, 8, 58, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Progress1 = GUICtrlCreateProgress(64, 120, 305, 9)
$Label2 = GUICtrlCreateLabel("Status..:", 16, 120, 43, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Label4 = GUICtrlCreateLabel("Größe änderen", 16, 144, 75, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Inp_X = GUICtrlCreateInput("1024", 104, 136, 33, 21)
$Label5 = GUICtrlCreateLabel("X", 144, 137, 15, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$Inp_Y = GUICtrlCreateInput("1024", 168, 136, 33, 21)
$Label6 = GUICtrlCreateLabel("Pixel", 208, 137, 36, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
$hBtn_Rename = GUICtrlCreateButton("Nur Konvertieren", 144, 168, 91, 25)
$hBtn_Resize = GUICtrlCreateButton("Größe ändern", 240, 168, 107, 25)
$Input2 = GUICtrlCreateInput("", 8, 88, 313, 21)
$hBtn_Search2 = GUICtrlCreateButton("Durchsuchen", 328, 85, 75, 25)
$Label7 = GUICtrlCreateLabel("Speicherort", 8, 64, 58, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hBtn_Search
$szPath = FileOpenDialog("Bild öffnen", "", "Bilder (*.jpg;*.bmp;*.png)", 3) ; Datei auswählen
If Not @error Then
GUICtrlSetData($Input1, $szPath)
$szPath = StringReplace($szPath, StringTrimLeft($szPath, StringInStr($szPath, ".", "", -1) ), "jpg")
GUICtrlSetData($Input2, $szPath)
EndIf
Case $hBtn_Search2
$szPath = FileOpenDialog("Speichern unter", "", "JPG-Bild (*.jpg)", 3) ; Datei auswählen
If Not @error Then GUICtrlSetData($Input2, $szPath)
Case $hBtn_Resize
_ImageResize()
;~ $fScaleX = GUICtrlRead($Inp_X) / _GDIPlus_ImageGetWidth($hImage) ; Ermittle die Größenverhältnisse
;~ $fScaleY = GUICtrlRead($Inp_Y) / _GDIPlus_ImageGetHeight($hImage)
;~ If (_GDIPlus_ImageGetWidth($hImage) * $fScaleY) <= GUICtrlRead($Inp_X) Then ; Richtigen Faktor ermitteln
;~ $fScale = $fScaleX
;~ Else
;~ $fScale = $fScaleY
;~ EndIf
;~ $hMatrix = _GDIPlus_MatrixCreate()
;~ _GDIPlus_MatrixScale($hMatrix, $fScale, $fScale) ; Maske festlegen
;~ MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$fScale' & @lf & @lf & 'Return:' & @lf & $fScale & @lf & @lf & '@Error:' & @lf & @Error & @lf & @lf & '@Extended:' & @lf & @Extended) ;### Debug MSGBOX
;~ $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)
;~ _GDIPlus_GraphicsSetTransform($hGraphics, $hMatrix) ; Änderungen anwenden
;~ _GDIPlus_ImageSaveToFile($hImage, GUICtrlRead($Input2) ) ; Bild Speichern
[/autoit] [autoit][/autoit] [autoit];~ _GDIPlus_MatrixDispose($hMatrix) ; Ressourcen freigeben
;~ _GDIPlus_ImageDispose($hImage)
;~ _GDIPlus_GraphicsDispose($hGraphics)
;~ _GDIPlus_Shutdown()
Case $hBtn_Rename
_GDIPlus_Startup()
If Not FileExists(GUICtrlRead($Input1)) Then ContinueLoop
$hImage = _GDIPlus_ImageLoadFromFile(GUICtrlRead($Input1))
If @error Then ContinueLoop
_GDIPlus_ImageSaveToFile($hImage, GUICtrlRead($Input2))
_GDIPlus_Shutdown()
EndSwitch
WEnd
Func _ImageResize()
Local $hwnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0, $X, $Y
_GDIPlus_Startup()
If Not FileExists(GUICtrlRead($Input1)) Then Return
$hImage2 = _GDIPlus_ImageLoadFromFile(GUICtrlRead($Input1))
If @error Then Return
; X +++UND+++ Y müssen kleiner-gleich mit den Eingaben sein. Das Verhältnis wird jedoch beibehalten
;
; Bsp:
; Eingaben: 800/600 Bild: 1000/500
; Scales: 0.75/1.2
; Damit das Verhältnis 2:1 bleibt, wird ein Faktor 2 mal benutzt
; 1.2 * 1000 ist aber nicht <= als die eingegebene Bildgröße, deswegen wird 0.75 benutzt.
; Ausgabebild: 800/400
$X = _GDIPlus_ImageGetWidth($hImage1)
$Y = _GDIPlus_ImageGetHeight($hImage1)
$iW = GUICtrlRead($Inp_X)
$iH = GUICtrlRead($Inp_Y)
If $X > $Y Then
$iH = $Y * ($X / $iW)
Else
$iW = $X * ($Y / $iH)
EndIf
$hwnd = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($hwnd)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH)
_WinAPI_ReleaseDC($hwnd, $hDC)
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
;~ $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH)
$CLSID = _GDIPlus_EncodersGetCLSID("JPG")
_GDIPlus_ImageSaveToFileEx($hImage1, GUICtrlRead($Input2), $CLSID)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
EndFunc ;==>_ImageResize