Hallo Leute,
seit langer Zeit mal wieder ein kleines Script was vielleicht der ein oder andere gebrauchen kann:
Es ist ein Programm das eure Bilder in neuer größe rendert.
Die Eingabeformate sind: GIF, BMP, JPG, JPEG, PNG
Das Ausgabeformat ist: PNG
Die UDF:
UDF
#include <GDIPlus.au3>
Global $hGraphic, $hBitmap, $hBackbuffer, $sGui, $sPicture
; Type: 0 = Smoothing
; 1 = no Smoothing
Func _ReSize($ImageFile, $Width, $Height, $Output, $Type = 0)
_GDIPlus_Startup()
$sGui = GUICreate("ReSize", $Width, $Height, -1, -1)
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($sGui)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $hGraphic)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$sPicture = _GDIPlus_ImageLoadFromFile($ImageFile)
If @error Then
Return 0
EndIf
If $Type = 1 Then
_GDIPlus_GraphicsSetPixelOffsetMode($hBackbuffer, 2)
_GDIPlus_GraphicsSetInterpolationMode($hBackbuffer, 5)
_GDIPlus_GraphicsDrawImageRect($hBackbuffer, $sPicture, 0, 0, $Width, $Height)
_GDIPlus_ImageSaveToFile($hBitmap, $Output)
_GDIPlus_Shutdown()
Return 2
ElseIf $Type = 0 Then
_GDIPlus_GraphicsSetPixelOffsetMode($hBackbuffer, 2)
_GDIPlus_GraphicsDrawImageRect($hBackbuffer, $sPicture, 50, 50, $Width, $Height)
_GDIPlus_ImageSaveToFile($hBitmap, $Output)
_GDIPlus_Shutdown()
Return 1
EndIf
_GDIPlus_Shutdown()
Return False
EndFunc ;==>_ReSize
Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "hwnd", $hGraphics, "int", $iInterpolationMode)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsSetInterpolationMode
;5 = Non Smoothing
Func _GDIPlus_GraphicsSetPixelOffsetMode($hGraphics, $iPixelOffsetMode)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetPixelOffsetMode", "hwnd", $hGraphics, "int", $iPixelOffsetMode)
If @error Then Return SetError(@error, @extended, False)
$GDIP_STATUS = $aResult[0]
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsSetPixelOffsetMode
Ein kleines Programm dazu:
Programm
#include <ReSize.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("ReSizeR", 154, 192, -1, -1)
$Label1 = GUICtrlCreateLabel("Image:", 8, 8, 59, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$pImage = GUICtrlCreateInput("-1", 72, 8, 73, 21)
GUICtrlSetState(-1, $GUI_HIDE)
$bImage = GUICtrlCreateButton("Open...", 72, 8, 73, 21)
$Label2 = GUICtrlCreateLabel("Width:", 8, 40, 55, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Width = GUICtrlCreateInput("Width", 72, 40, 73, 21)
$Label3 = GUICtrlCreateLabel("Height:", 8, 72, 62, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Height = GUICtrlCreateInput("Height", 72, 72, 73, 21)
$Label4 = GUICtrlCreateLabel("Smoothing", 32, 104, 90, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Yes = GUICtrlCreateRadio("Yes", 8, 136, 49, 17)
$No = GUICtrlCreateRadio("No", 80, 136, 65, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Render = GUICtrlCreateButton("Render", 32, 160, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $bImage
$oImage = FileOpenDialog("Open Image...", @DesktopDir, "PNG (*.png)|JPG (*.jpg)|JPEG (*.jpeg)|GIF (*.gif)|BMP (*.bmp)")
If @error Then
Else
GUICtrlSetState($bImage, $GUI_HIDE)
GUICtrlSetState($pImage, $GUI_SHOW)
GUICtrlSetData($pImage, $oImage)
GUICtrlSetState($pImage, $GUI_DISABLE)
EndIf
Case $Render
If GUICtrlRead($pImage) = "-1" Then
Else
$iSave = FileSaveDialog("Save Image...", @DesktopDir, "PNG (*.png)")
If @error Then
Else
If GUICtrlRead($Width) < 0 Or GUICtrlRead($Height) < 0 Then
Else
If BitAND(GUICtrlRead($Yes), $GUI_CHECKED) = $GUI_CHECKED Then
_ReSize(GUICtrlRead($pImage), GUICtrlRead($Width), GUICtrlRead($Height), $iSave & ".png")
ElseIf BitAND(GUICtrlRead($No), $GUI_CHECKED) = $GUI_CHECKED Then
_ReSize(GUICtrlRead($pImage), GUICtrlRead($Width), GUICtrlRead($Height), $iSave & ".png", 1)
EndIf
EndIf
EndIf
MsgBox(0, "Finish", "Process success.")
EndIf
EndSwitch
WEnd
Special Thanks an:
- Eucalyptus
- Die GDIP.au3 (Authenticity)
Ich hoffe ihr könnt es irgendwann mal gebrauchen, MfG Mattthias