Your matrix is rotating around the bottom right corner, set the matrix to rotate around the centre (half the image width, half the image height, line 42). You will also need to offset the drawn graphic by that much to compensate (line 66). Test label on line 63. You've also got a memory leak, but that's for you to track
#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $hAttribute_Alpha
Global $tColorMatrix
Global $g_back
Global $g_Needle
Global $g_hImage_Background
Global $g_hImage_Needle
Global $g_hGfx_Background
Global $g_hGfx_needle
Global $hMatrix
GUISetState()
$g_hGUI = GUICreate("Test", 356, 356, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW))
_GDIPlus_Startup()
$Needle = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\needle.png")
$Background = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\back.png")
Func _CreateGraphic()
$hAttribute_Alpha = _GDIPlus_ImageAttributesCreate()
$tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, 0) ;0 = opaque, -1 = transparent
_GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, DllStructGetPtr($tColorMatrix))
$g_back = _GDIPlus_ImageGetDimension($Background)
$g_Needle = _GDIPlus_ImageGetDimension($Needle)
$g_hImage_Background = _GDIPlus_BitmapCreateFromScan0($g_back[0], $g_back[1]) ; Creeaza imaginea dupa dimensiunile pozei incarcate mai sus
$g_hImage_Needle = _GDIPlus_BitmapCreateFromScan0($g_Needle[0], $g_Needle[1]) ; Adaugat
$g_hGfx_Background = _GDIPlus_ImageGetGraphicsContext($g_hImage_Background)
$g_hGfx_needle = _GDIPlus_ImageGetGraphicsContext($g_hImage_Needle) ; Adaugat
_GDIPlus_GraphicsDrawImageRectRect($g_hGfx_Background, $Background, 0, 0, $g_back[0], $g_back[1], 0, 0, $g_back[0], $g_back[1], $hAttribute_Alpha)
$hMatrix = _GDIPlus_MatrixCreate()
_GDIPlus_MatrixTranslate($hMatrix, $g_Needle[0]/2, $g_Needle[1]/2)
EndFunc
; Loop until user exits
$Rotation = 0
;Do
While Not GUIGetMsg() = $GUI_EVENT_CLOSE
If $Rotation=365 Then
$Rotation=0
EndIf
__Rotate($Rotation)
$Rotation += 5;
ConsoleWrite($Rotation & @CRLF)
Sleep(1000)
WEnd
Func __Rotate($i)
_CreateGraphic()
_GDIPlus_GraphicsClear($g_hGfx_needle, 0xFF000000)
_GDIPlus_GraphicsDrawImageRectRect($g_hGfx_Background, $Background, 0, 0, $g_back[0], $g_back[1], 0, 0, $g_back[0], $g_back[1], $hAttribute_Alpha)
$g_hGfx_Background = _GDIPlus_ImageGetGraphicsContext($g_hImage_Background)
_GDIPlus_GraphicsDrawString($g_hGfx_Background, "Test", $g_back[0]/2, 30)
_GDIPlus_MatrixRotate($hMatrix, $i)
_GDIPlus_GraphicsSetTransform($g_hGfx_Background, $hMatrix)
_GDIPlus_GraphicsDrawImageRect($g_hGfx_Background, $Needle, -$g_Needle[0]/2, -$g_Needle[1]/2, $g_Needle[0], $g_Needle[1])
SetBitmap($g_hGUI, $g_hImage_Background, 255)
GUISetState()
EndFunc
IF GUIGetMsg=$GUI_EVENT_CLOSE Then
_GDIPlus_MatrixDispose($hMatrix)
_GDIPlus_ImageAttributesDispose($hAttribute_Alpha)
_GDIPlus_ImageDispose($Needle)
_GDIPlus_ImageDispose($g_hImage_Background)
_GDIPlus_ImageDispose($Background)
_GDIPlus_GraphicsDispose($g_hGfx_Background)
_GDIPlus_Shutdown()
EndIf
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", 1)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap