GUI ruckelt

  • Hi,
    folgendes Skript funktioniert so weit ganz gut

    Spoiler anzeigen
    [autoit]

    #region ;************ Includes ************
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #endregion ;************ Includes ************

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

    Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert

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

    Global $hPreviewBitmap

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

    Global $datei1 = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"

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

    _GDIPlus_Startup() ;Vorschau

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

    Global $hPreviewGui = GUICreate("Foto", 350, 250)
    Global $hPreviewGraphic = _GDIPlus_GraphicsCreateFromHWND($hPreviewGui)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
    GUISetState()

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

    _PreviewLoadImage($datei1)
    GUIRegisterMsg($WM_PAINT, 'WM_PAINT')

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

    While 1
    Sleep(10)
    WEnd

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

    Func _beenden()
    _GDIPlus_BitmapDispose($hPreviewBitmap)
    _GDIPlus_GraphicsDispose($hPreviewGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_beenden

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

    Func _PreviewLoadImage($sImgFile)
    $hPreviewBitmap = _GDIPlus_BitmapCreateFromFile($sImgFile)
    _GDIPlus_GraphicsDrawImageRect($hPreviewGraphic, $hPreviewBitmap, 10, 10, 300, 200)
    EndFunc ;==>_PreviewLoadImage

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

    Func WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    If $hWnd = $hPreviewGui Then _GDIPlus_GraphicsDrawImageRect($hPreviewGraphic, $hPreviewBitmap, 10, 10, 300, 200)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

    [/autoit]

    Wenn ich jedoch die GUI teilweise aus dem Bildschirm rein- und wieder rausschiebe, so ruckelt die GUI etwas.
    Dies leigt wohl am neuzeichnen der Grafik.

    Kann man dies irgendwie verhindern?

    Getestet mit Win 7 64bit.

  • Ich meinte eher eine Art Animation. Ansonsten kannst du mehrere Bilder in verschiedene Picture Controls reinkopieren und fertig.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Sorry, verstehe nur Bahnhof.
    Wofür eine Animation ?(
    Außerdem will ich die Größe des Bildes beim erstellen selbst bestimmen können.
    Es soll nachträglich noch ein anderes Bild geladen werden können (statt dem bereits vorhandenen.

  • Probiere es mal damit:

    Spoiler anzeigen
    [autoit]


    #region ;************ Includes ************
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #endregion ;************ Includes ************

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

    Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert

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

    Global Const $IMAGE_BITMAP = 0
    Global Const $STM_SETIMAGE = 0x0172
    Global $hPreviewBitmap

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

    Global $datei1 = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"

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

    _GDIPlus_Startup() ;Vorschau

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

    Global $hPreviewGui = GUICreate("Foto", 710, 350)
    Global $idPreviewPic = GUICtrlCreatePic("", 10, 10, 300, 200)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Global $idPreviewPic2 = GUICtrlCreatePic("", 400, 10, 200, 300)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Global $idButtonLoad = GUICtrlCreateButton("Laden", 300, 250, 60, 40)
    GUICtrlSetOnEvent(-1, "Load")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
    _PreviewLoadImage($datei1, $idPreviewPic, 300, 200)
    GUISetState()

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

    While 1
    Sleep(10)
    WEnd

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

    Func _beenden()
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_beenden

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

    Func Load()
    Local $file = FileOpenDialog("Suche ein Bild aus", "", "Bilder (*.jpg;*png;*.bmp;*.gif)")
    If @error Then Return
    _PreviewLoadImage($file, $idPreviewPic2, 300, 200, 7, 1, 1)
    EndFunc

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

    ; $iRotateFlipType - Type of rotation and flip:
    ; |0 - No rotation and no flipping (A 180-degree rotation, a horizontal flip and then a vertical flip)
    ; |1 - A 90-degree rotation without flipping (A 270-degree rotation, a horizontal flip and then a vertical flip)
    ; |2 - A 180-degree rotation without flipping (No rotation, a horizontal flip folow by a vertical flip)
    ; |3 - A 270-degree rotation without flipping (A 90-degree rotation, a horizontal flip and then a vertical flip)
    ; |4 - No rotation and a horizontal flip (A 180-degree rotation followed by a vertical flip)
    ; |5 - A 90-degree rotation followed by a horizontal flip (A 270-degree rotation followed by a vertical flip)
    ; |6 - A 180-degree rotation followed by a horizontal flip (No rotation and a vertical flip)
    ; |7 - A 270-degree rotation followed by a horizontal flip (A 90-degree rotation followed by a vertical flip)

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

    Func _PreviewLoadImage($sImgFile, $CtrlID, $iW, $iH, $iInterpolationMode = 7, $iRotateFlipType = 0, $clear = 0)
    If $clear Then GUICtrlSendMsg($CtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, 0)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImgFile)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hGfxCtxt, "int", $iInterpolationMode)
    _GDIPlus_GraphicsDrawImageRect($hGfxCtxt, $hImage, 0, 0, $iW, $iH)
    If $iRotateFlipType Then DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "hwnd", $hBitmap, "int", $iRotateFlipType)
    Local $hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _WinAPI_DeleteObject(GUICtrlSendMsg($CtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
    EndFunc ;==>_PreviewLoadImage

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

    Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')
    DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 2, $Ret[2])
    DllStructSetData($tBIHDR, 3, $Ret[3])
    DllStructSetData($tBIHDR, 4, 1)
    DllStructSetData($tBIHDR, 5, 32)
    DllStructSetData($tBIHDR, 6, 0)
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
    DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
    $hResult = $hResult[0]
    Else
    $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
    EndFunc ;==>_GDIPlus_BitmapCreateDIBFromBitmap

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (1. Januar 2012 um 16:47)

  • Wow 8o
    funktioniert sehr gut.

    Muß man unbedingt 2x GuiCtrlCreatePic nehmen?
    Oder geht es so wie im Skript.

    Spoiler anzeigen
    [autoit]

    #region ;************ Includes ************
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #endregion ;************ Includes ************

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

    Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert

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

    Global Const $IMAGE_BITMAP = 0
    Global Const $STM_SETIMAGE = 0x0172
    Global $hPreviewBitmap

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

    Global $datei1 = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"

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

    _GDIPlus_Startup() ;Vorschau

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

    Global $hPreviewGui = GUICreate("Foto", 710, 300)
    Global $idPreviewPic = GUICtrlCreatePic("", 10, 10, 300, 200)
    GUICtrlSetState(-1, $GUI_DISABLE)
    ;~ Global $idPreviewPic2 = GUICtrlCreatePic("", 400, 10, 300, 200)
    ;~ GUICtrlSetState(-1, $GUI_DISABLE)
    Global $idButtonLoad = GUICtrlCreateButton("Laden", 400, 250, 60, 40)
    GUICtrlSetOnEvent(-1, "Load")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")
    _PreviewLoadImage($datei1, $idPreviewPic, 300, 200)
    GUISetState()

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

    While 1
    Sleep(10)
    WEnd

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

    Func _beenden()
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_beenden

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

    Func Load()
    Local $file = FileOpenDialog("Suche ein Bild aus", "", "Bilder (*.jpg;*png;*.bmp;*.gif)")
    If @error Then Return
    ;~ _PreviewLoadImage($file, $idPreviewPic2, 300, 200)
    _PreviewLoadImage($file, $idPreviewPic, 300, 200)
    EndFunc ;==>Load

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

    Func _PreviewLoadImage($sImgFile, $CtrlID, $iW, $iH, $iInterpolationMode = 7)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImgFile)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hGfxCtxt, "int", $iInterpolationMode)
    _GDIPlus_GraphicsDrawImageRect($hGfxCtxt, $hImage, 0, 0, $iW, $iH)
    Local $hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _WinAPI_DeleteObject(GUICtrlSendMsg($CtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
    EndFunc ;==>_PreviewLoadImage

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

    Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')
    DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 2, $Ret[2])
    DllStructSetData($tBIHDR, 3, $Ret[3])
    DllStructSetData($tBIHDR, 4, 1)
    DllStructSetData($tBIHDR, 5, 32)
    DllStructSetData($tBIHDR, 6, 0)
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
    DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
    $hResult = $hResult[0]
    Else
    $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
    EndFunc ;==>_GDIPlus_BitmapCreateDIBFromBitmap

    [/autoit]

    Hat deine Version Nachteile gegenüber meiner Version aus dem ersten Post ^^

  • Natürlich muss man nicht 2x GuiCtrlCreatePic, aber ich hatte dich so verstanden.

    Gruß,
    UEZ

    PS: viele Wege führen nach Rom...

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Hatte gestern auch ein Problem mit einer .png-Datei. Da ich das Bild in einem Tab-Control darstellen musste, kam die GDI+ Variante (aus der Hilfe) für mich nicht in Frage.
    Hab dann etwas in Google geblättert und eine Funktion zum Umwandeln von .png in .jpg gefunden.
    Sieht, nachdem ich's für mich angepasst hatte, in etwa so aus:

    [autoit]

    #include <GDIPlus.au3>

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

    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild.png") ;Pfad zur .png

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

    Func _PNGtoJPG($PNG)
    Local $hImage, $sCLSID
    Local $File = FileGetLongName($PNG)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($File)
    $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    Local $NewJpg = StringTrimRight($File, 4)&".jpg"
    Local $Check = _GDIPlus_ImageSaveToFileEx($hImage, $NewJpg, $sCLSID)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    If $Check = True Then
    Return($NewJpg) ;Pfad zur neu erstellten .jpg
    ElseIf $Check = False Then
    Return(-1) ; ansonsten Rückgabewert "-1"
    EndIf
    EndFunc ;==>_PNGtoJPG

    [/autoit]

    Edit: Wie UEZ schon sagte: Viele Wege führen nach Rom

    UNPLEASANT SPOILER

    You just lost the game!

    Einmal editiert, zuletzt von shadow667 (31. Dezember 2011 um 15:00)

  • Noch ne eher allgemeine Frage zu GDIplus.

    Gibt es eigentliche Nachteile wenn _GDIPlus_Startup() mehrmals aufgerufen wird ohne vorher durch _GDIPlus_Shutdown() beendet worden zu sein?

    Es würde ja mehrere Möglichkeiten geben wo _GDIPlus_Startup() und _GDIPlus_Shutdown() hingeschrieben wird.

    V1

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild1.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild2.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild3.png") ;Pfad zur .png

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

    Func _PNGtoJPG($PNG)
    Local $hImage, $sCLSID
    Local $File = FileGetLongName($PNG)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($File)
    $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    Local $NewJpg = StringTrimRight($File, 4)&".jpg"
    Local $Check = _GDIPlus_ImageSaveToFileEx($hImage, $NewJpg, $sCLSID)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    If $Check = True Then
    Return($NewJpg) ;Pfad zur neu erstellten .jpg
    ElseIf $Check = False Then
    Return(-1) ; ansonsten Rückgabewert "-1"
    EndIf
    EndFunc ;==>_PNGtoJPG

    [/autoit]

    V2

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    _GDIPlus_Startup()

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

    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild1.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild2.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild3.png") ;Pfad zur .png

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

    _GDIPlus_Shutdown()

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

    Func _PNGtoJPG($PNG)
    Local $hImage, $sCLSID
    Local $File = FileGetLongName($PNG)
    $hImage = _GDIPlus_ImageLoadFromFile($File)
    $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    Local $NewJpg = StringTrimRight($File, 4)&".jpg"
    Local $Check = _GDIPlus_ImageSaveToFileEx($hImage, $NewJpg, $sCLSID)
    _GDIPlus_ImageDispose($hImage)
    If $Check = True Then
    Return($NewJpg) ;Pfad zur neu erstellten .jpg
    ElseIf $Check = False Then
    Return(-1) ; ansonsten Rückgabewert "-1"
    EndIf
    EndFunc ;==>_PNGtoJPG

    [/autoit]

    V3

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    _GDIPlus_Startup()

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

    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild1.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild2.png") ;Pfad zur .png
    $Pic = _PNGtoJPG(@ScriptDir&"\DeinBild3.png") ;Pfad zur .png

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

    _GDIPlus_Shutdown()

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

    Func _PNGtoJPG($PNG)
    Local $hImage, $sCLSID
    Local $File = FileGetLongName($PNG)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($File)
    $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    Local $NewJpg = StringTrimRight($File, 4)&".jpg"
    Local $Check = _GDIPlus_ImageSaveToFileEx($hImage, $NewJpg, $sCLSID)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    If $Check = True Then
    Return($NewJpg) ;Pfad zur neu erstellten .jpg
    ElseIf $Check = False Then
    Return(-1) ; ansonsten Rückgabewert "-1"
    EndIf
    EndFunc ;==>_PNGtoJPG

    [/autoit]
  • Also ich würde sagen (hab allerdings nicht allzuviel Erfahrung mit GDI+), daß, wenn du im Script weiter mit GDI+ arbeiten willst, es einmal am Scriptanfang zu starten und dann vor'm Exit wieder zu beenden. Die Funktion wäre dann wie in deiner V2

    Edit: Ich verwende die Funktion mit Arrays + For-Next Schleife und lösche die .jpg's beim Beenden des Scripts wieder, etwa so:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    Global $PNG_Bilder[4] = [@ScriptDir&"\Bild1.png", @ScriptDir&"\Bild2.png",@ScriptDir&"\Bild3.png",@ScriptDir&"\Bild4.png"]
    Global $JPG_Bilder[4]

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

    For $i = 0 to 3
    $JPG_Bilder[$i] = _PNGtoJPG($PNG_Bilder[$i])
    Next

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

    OnAutoItExitRegister("_DelJPGFiles")

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

    Func _PNGtoJPG($PNG)
    Local $hImage, $sCLSID
    Local $File = FileGetLongName($PNG)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($File)
    $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
    Local $NewJpg = StringTrimRight($File, 4)&".jpg"
    Local $Check = _GDIPlus_ImageSaveToFileEx($hImage, $NewJpg, $sCLSID)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    If $Check = True Then
    Return($NewJpg) ;Pfad zur neu erstellten .jpg
    ElseIf $Check = False Then
    Return(-1) ; ansonsten Rückgabewert "-1"
    EndIf
    EndFunc ;==>_PNGtoJPG

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

    Func _DelJPGFiles()
    For $i = 0 To 3
    FileDelete($JPG_Bilder[$i])
    Next
    EndFunc

    [/autoit]
    UNPLEASANT SPOILER

    You just lost the game!

    2 Mal editiert, zuletzt von shadow667 (31. Dezember 2011 um 15:43)

  • Nun will ich das Bild noch um 90° drehen.
    Ich hab zwar das Bsp aus der Hilfe gefunden, jedoch will ich das Bild nicht speichern, sondern nur anzeigen

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <ScreenCapture.au3>

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

    Opt('MustDeclareVars', 1)

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

    _Main()

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

    Func _Main()
    Local $hBitmap, $hImage, $sCLSID, $tData, $tParams

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

    ; Erstellt vom kompletten Bildschirm einen Screenshot
    _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.jpg")

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

    ; Initialisiert (startet) Microsoft Windows GDI+
    _GDIPlus_Startup()

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

    ; Lädt ein Bild
    $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg")

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

    ; Gibt die Encoder CLSID für einen festgelegten Bild-Dateityp zurück
    $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")

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

    ; Setzt die Parameter für eine 90 Grad Rotation
    $tData = DllStructCreate("int Data")
    DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90)
    $tParams = _GDIPlus_ParamInit(1)
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))

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

    ; Speichert das gedrehte Bild
    _GDIPlus_ImageSaveToFileEx($hImage, @MyDocumentsDir & "\GDIPlus_Image2.jpg", $sCLSID, DllStructGetPtr($tParams))

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

    ; Gibt die durch Microsoft Windows GDI+ verwendeten Ressourcen wieder frei
    _GDIPlus_Shutdown()

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

    EndFunc ;==>_Main

    [/autoit]
  • Ich habe den Code im Beitrag #6 modifiziert, so dass du das Bild in 90° Schritten drehen kannst.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Es kommt darauf an, was du im Gesamten machen willst.

    Wenn du weißt, dass du viele GDI+ Funktionienen benutzt, macht es keinen Sinn in der Funktion _GDIPlus_Startup() und _GDIPlus_Shutdown() ständig zu benutzen, denn es kostet Zeit. Ein paar mal _GDIPlus_Startup() und _GDIPlus_Shutdown() aufrufen ist aber verkraftbar.

    _GDIPlus_Startup() am Anfang aufrufen und _GDIPlus_Shutdown() beim Beenden ist wohl die beste Lösung, denn ich sehe keinen Nachteil, auch wenn du keine GDI+ Funktionienen benutzt.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • So, muß den Thread leider nochmals ausgraben.

    Wenn ich das Skript minimiere bevor das Bild gezeichnet wird, wird deren Größe nicht übernommen (siehe Zeile 27)
    Weiß einer warum?
    Komme leider nicht weiter.

    Spoiler anzeigen
    [autoit]

    #region ;************ Includes ************
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    #endregion ;************ Includes ************

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

    Opt("GUIOnEventMode", 1) ; 0=ausgeschaltet, 1=OnEvent Modus aktiviert

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

    Global Const $IMAGE_BITMAP = 0
    Global Const $STM_SETIMAGE = 0x0172
    Global $hPreviewBitmap

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

    Global $datei1 = "C:\Windows\Web\Wallpaper\Windows\img0.jpg"

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

    _GDIPlus_Startup() ;Vorschau

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

    Global $hPreviewGui = GUICreate("Foto", 710, 350)
    Global $idPreviewPic = GUICtrlCreatePic("", 10, 10, 300, 200)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Global $idPreviewPic2 = GUICtrlCreatePic("", 400, 10, 200, 300)
    GUICtrlSetState(-1, $GUI_DISABLE)
    Global $idButtonLoad = GUICtrlCreateButton("Laden", 300, 250, 60, 40)
    GUICtrlSetOnEvent(-1, "Load")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_beenden")

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

    WinSetState("Foto", "", @SW_MINIMIZE) ;wenn aktiv wird in der nächsten Zeile die Größe 600 bzw. 100 ignoriert
    _PreviewLoadImage($datei1, $idPreviewPic, 600, 100)
    WinSetState("Foto", "", @SW_RESTORE)
    GUISetState()

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

    While 1
    Sleep(10)
    WEnd

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

    Func _beenden()
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_beenden

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

    Func Load()
    Local $file = FileOpenDialog("Suche ein Bild aus", "", "Bilder (*.jpg;*png;*.bmp;*.gif)")
    If @error Then Return
    _PreviewLoadImage($file, $idPreviewPic2, 300, 200, 7, 1, 1)
    EndFunc

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

    ; $iRotateFlipType - Type of rotation and flip:
    ; |0 - No rotation and no flipping (A 180-degree rotation, a horizontal flip and then a vertical flip)
    ; |1 - A 90-degree rotation without flipping (A 270-degree rotation, a horizontal flip and then a vertical flip)
    ; |2 - A 180-degree rotation without flipping (No rotation, a horizontal flip folow by a vertical flip)
    ; |3 - A 270-degree rotation without flipping (A 90-degree rotation, a horizontal flip and then a vertical flip)
    ; |4 - No rotation and a horizontal flip (A 180-degree rotation followed by a vertical flip)
    ; |5 - A 90-degree rotation followed by a horizontal flip (A 270-degree rotation followed by a vertical flip)
    ; |6 - A 180-degree rotation followed by a horizontal flip (No rotation and a vertical flip)
    ; |7 - A 270-degree rotation followed by a horizontal flip (A 90-degree rotation followed by a vertical flip)

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

    Func _PreviewLoadImage($sImgFile, $CtrlID, $iW, $iH, $iInterpolationMode = 7, $iRotateFlipType = 0, $clear = 0)
    If $clear Then GUICtrlSendMsg($CtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, 0)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImgFile)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hGfxCtxt, "int", $iInterpolationMode)
    _GDIPlus_GraphicsDrawImageRect($hGfxCtxt, $hImage, 0, 0, $iW, $iH)
    If $iRotateFlipType Then DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "hwnd", $hBitmap, "int", $iRotateFlipType)
    Local $hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGfxCtxt)
    _WinAPI_DeleteObject(GUICtrlSendMsg($CtrlID, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap))
    EndFunc ;==>_PreviewLoadImage

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

    Func _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap)
    Local $tBIHDR, $Ret, $tData, $pBits, $hResult = 0
    $Ret = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
    If (@error) Or ($Ret[0]) Then Return 0
    $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $Ret[2], $Ret[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB)
    $pBits = DllStructGetData($tData, 'Scan0')
    If Not $pBits Then Return 0
    $tBIHDR = DllStructCreate('dword;long;long;ushort;ushort;dword;dword;long;long;dword;dword')
    DllStructSetData($tBIHDR, 1, DllStructGetSize($tBIHDR))
    DllStructSetData($tBIHDR, 2, $Ret[2])
    DllStructSetData($tBIHDR, 3, $Ret[3])
    DllStructSetData($tBIHDR, 4, 1)
    DllStructSetData($tBIHDR, 5, 32)
    DllStructSetData($tBIHDR, 6, 0)
    $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0)
    If (Not @error) And ($hResult[0]) Then
    DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $Ret[2] * $Ret[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0'))
    $hResult = $hResult[0]
    Else
    $hResult = 0
    EndIf
    _GDIPlus_BitmapUnlockBits($hBitmap, $tData)
    Return $hResult
    EndFunc ;==>_GDIPlus_BitmapCreateDIBFromBitmap

    [/autoit]
  • Du musst die Größe des Control mitanpassen:

    [autoit]


    ...
    WinSetState("Foto", "", @SW_MINIMIZE) ;wenn aktiv wird in der nächsten Zeile die Größe 600 bzw. 100 ignoriert
    GUICtrlSetPos($idPreviewPic, 10, 10, 600, 100)
    _PreviewLoadImage($datei1, $idPreviewPic, 600, 100)
    WinSetState("Foto", "", @SW_RESTORE)
    ...

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Hm, ok so scheint es zu funktionieren.
    Jedoch verstehe ich es nicht ganz warum dem so ist.
    Wenn ich die GUI vorher nicht minimiere funktioniert es ja auch ohne anpassen der Größe.