#SOLVED
Working GIF Animation with Rotation:
(Thanks to AVS for the help!)
AutoIt
#AutoIt3Wrapper_Res_File_Add=gif-Green-UFO.gif, rt_rcdata, ANI_GIF_1
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <Timers.au3>
#include "resources.au3"
HotKeySet("{Esc}", "Quit")
HotKeySet("{Left}", "Left")
HotKeySet("{Right}", "Right")
HotKeySet("{Pause}", "Pause")
Global $GIF_TimerID, $hImage, $GFC, $GFDC, $pDimensionIDs, $tDL
Global $Pause, $i = 0
Global $GUI_Width = 400
Global $GUI_Height = 400
Global $Gdi_x1 = 0
Global $Gdi_y1 = 0
Global $Gdi_x2 = $GUI_Width
Global $Gdi_y2 = $GUI_Height
$mainGui = GUICreate("GIF Animation", $GUI_Width, $GUI_Height)
GUISetState(@SW_SHOW)
_GDIPlus_Startup()
$graphic = _GDIPlus_GraphicsCreateFromHWND($mainGui) ; Frontbuffer
$bitmap = _GDIPlus_BitmapCreateFromGraphics($Gdi_x2, $Gdi_y2, $graphic) ; x2, y2
$buffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ; Backbuffer
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\diamond.gif")
$imgX1 = _GDIPlus_ImageGetWidth($hImage)
$imgY1 = _GDIPlus_ImageGetHeight($hImage)
$gdiBg = _GDIPlus_BrushCreateSolid(0xFFBDBDBD)
$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, $imgX1 / 2, $imgY1 / 2)
GifInit()
; Start Animation: instead of using the time delays between frames given from GIF we use 100ms for simplicity
_Timer_SetTimer($mainGui, 32, "_Draw_Timer")
While 1
If GUIGetMsg() = -3 Then Quit()
WEnd
Func _Draw_Timer($hWnd, $Msg, $iIDTimer, $dwTime)
If Not $Pause Then
If $i = $GFC Then $i = 0 ; If $i = the frame count then reset $i to 0
GifDrawFrame($i)
$i += 1
EndIf
EndFunc
Func Quit()
_GDIPlus_MatrixDispose($hMatrix)
_Timer_KillAllTimers($mainGui)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
HotKeySet("{Esc}")
HotKeySet("{Left}")
HotKeySet("{Right}")
HotKeySet("{Pause}")
Exit
EndFunc
Func GifInit()
; Load your animated GIF (from file or from resources)
;~ $hImage = _ResourceGetAsImage("ANI_GIF_1")
$tDL = DllStructCreate($tagGUID) ; Create a struct to hold the GUID.
$pDimensionIDs = DllStructGetPtr($tDL) ; Get a pointer to the GUID struct.
; Get the FrameDimensionsCount of the loaded gif
$GFDC = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "ptr", $hImage, "int*", 0)
; Get the FrameDimensionsList , which fills the GUID struct by passing the GUID pointer and the FrameDimensionsCount.
DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsList", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $GFDC[2])
; Get the FrameCount of the loaded gif by passing the GUID pointer
$GFC = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameCount", "int", $hImage, "ptr", $pDimensionIDs, "int*", 0)
$GFC = $GFC[3]
EndFunc
Func GifDrawFrame($i)
; Select the ActiveFrame in the loaded GIF by telling it. The frame starts at 0 ($i)
DllCall($__g_hGDIPDll, "int", "GdipImageSelectActiveFrame", "ptr", $hImage, "ptr", $pDimensionIDs, "int", $i)
; get current frame from GIF and draw it on the control
_GDIPlus_GraphicsClear($buffer) ; Inhalt des Backbuffer`s wird gelöscht
;~ _GDIPlus_GraphicsFillRect($buffer, 0, 0, $Gdi_x2, $Gdi_y2, $gdiBg) ; draw map background
; rotation
_GDIPlus_MatrixRotate($hMatrix, 1, "False")
_GDIPlus_GraphicsSetTransform($buffer, $hMatrix)
;~ _GDIPlus_GraphicsDrawImageRect($buffer, $hImage, 0, 0, $imgX1, $imgY1)
_GDIPlus_GraphicsDrawImageRect($buffer, $hImage, -$imgX1 / 2, -$imgY1 / 2, $imgX1, $imgY1)
_GDIPlus_GraphicsDrawImage($graphic, $bitmap, $Gdi_x1, $Gdi_y1) ; Backbuffer wird an den Frontbuffer übergeben
EndFunc
Func Left()
If WinActive($mainGui) Then
If Not $Pause Then Return
$i -= 1
If $i = -1 Then $i = $GFC - 1
GifDrawFrame($i)
Else
HotKeySet("{Left}")
Send("{Left}")
HotKeySet("{Left}", "Left")
EndIf
EndFunc
Func Right()
If WinActive($mainGui) Then
If Not $Pause Then Return
$i += 1
If $i = $GFC Then $i = 0
GifDrawFrame($i)
Else
HotKeySet("{Right}")
Send("{Right}")
HotKeySet("{Right}", "Right")
EndIf
EndFunc
Func Pause()
If WinActive($mainGui) Then
$Pause = Not $Pause
If $Pause Then
WinSetTitle($mainGui, '', 'GIF Animation - PAUSED')
Else
WinSetTitle($mainGui, '', 'GIF Animation')
EndIf
Else
HotKeySet("{PAUSE}")
Send("{PAUSE}")
HotKeySet("{PAUSE}", "Pause")
EndIf
EndFunc
Alles anzeigen