GDI - Png drehen und auf Hintergrund zeichen

  • Hi,

    ich habe gerade das Problem, dass ein Png-Bild trotz MatrixRotate nicht gedreht wird. Das gedrehte Png-Bild soll anschließend, wieder auf einen Hintergrund gezeichnet werden.

    Mein Code:

    Spoiler anzeigen
    [autoit]


    _GDIPlus_Startup()
    $hImage_Background = _GDIPlus_BitmapCreateFromFile($_Path & "123.png")
    $hImage_Foreground = _GDIPlus_BitmapCreateFromFile($_Path & "xyz.png")

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

    Global $iWidth = _GDIPlus_ImageGetWidth($hImage_Background)
    Global $iHeight = _GDIPlus_ImageGetHeight($hImage_Background)

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

    Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWindow_Programm)
    Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    Global $hGraphic_Buffer = _GDIPlus_GraphicsCreateFromHWND($hWindow_Programm)
    Global $hBitmap_Buffer = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    Global $hBack_Buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)

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

    _GDIPlus_GraphicsDrawImage($hBack_Buffer, $hImage_Background, 0, 0) ;zeichnet das Hintergrundbild
    _GDIPlus_GraphicsDrawImage($hBack_Buffer, $hImage_Foreground, 480, 304) ;zeichnet das Vordergrundbild
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $bitmap, 24, 24, $iWidth, $iHeight) ;zeichnet die beiden Bilder die in $hGraphic gezeichnet wurden

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

    $hMatrix = _GDIPlus_MatrixCreate()
    ;_GDIPlus_MatrixTranslate($hMatrix,800,240)
    _GDIPlus_MatrixRotate($hMatrix, 90, "False")
    _GDIPlus_GraphicsSetTransform($hImage_Foreground, $hMatrix)
    _GDIPlus_GraphicsDrawImage($hBack_Buffer, $hImage_Background, 0, 0) ;zeichnet das Hintergrundbild
    _GDIPlus_GraphicsDrawImage($hBack_Buffer, $hImage_Foreground, 480, 304) ;zeichnet das Vordergrundbild
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap_Buffer, 24, 24, $iWidth, $iHeight);zeichnet die beiden Bilder die in $hGraphic gezeichnet wurden

    [/autoit]

    Zum besseren Verständnis eine "kleine Beschreibung" im Anhang.

  • Hier mein Lösungsvorschlag:

    Spoiler anzeigen
    [autoit]


    ;Coded by UEZ 2010-01-10
    #include <GDIplus.au3>
    Opt("GUIOnEventMode", 1)

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

    _GDIPlus_Startup()
    Global $load_background = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\Background.png")
    Global $load_foreground = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\Smiley.png")
    Global $width = _GDIPlus_ImageGetWidth($load_background)
    Global $height = _GDIPlus_ImageGetHeight($load_background)

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

    Global $dx = _GDIPlus_ImageGetWidth($load_foreground)
    Global $dy = _GDIPlus_ImageGetHeight($load_foreground)

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

    Global $i

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

    Global $hWnd = GUICreate("GDI+: Example by UEZ", $width, $height, -1, -1, Default)
    GUISetOnEvent(-3, "_Exit")
    GUISetState()

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

    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics)
    Global $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    Global $hFGBitmap = _GDIPlus_BitmapCreateFromGraphics($dx, $dy, $hGraphics)
    Global $hFGBackbuffer = _GDIPlus_ImageGetGraphicsContext($hFGBitmap)

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

    Global $hMatrix = _GDIPlus_MatrixCreate()
    _GDIPlus_MatrixTranslate($hMatrix, $dx / 2, $dy / 2)

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

    Global $FG_x = 0
    Global $FG_y = $height / 2 - $dy / 2

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

    Global $coordinate[1][2]
    $coordinate[0][0] = 0
    $coordinate[0][1] = 0
    $i = 6
    $j = 3
    While Sleep(30)
    _GDIPlus_GraphicsDrawImage($hBackbuffer, $load_background, 0, 0) ;draw background
    _GDIPlus_GraphicsClear($hFGBackbuffer, 0x00000000) ;clear backbuffer from foreground graphics

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

    _GDIPlus_MatrixRotate($hMatrix, $i, "False") ;rotate foreground graphic
    _GDIPlus_GraphicsSetTransform($hFGBackbuffer, $hMatrix)
    _GDIPlus_GraphicsDrawImage($hFGBackbuffer, $load_foreground, -$dx /2, -$dy / 2)

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

    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hFGBitmap, $FG_x, $FG_y, $dx, $dy) ;copy foreground backbuffer to main backbuffer
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $width, $height) ;copy full drawn image to main screen
    If $FG_x > $width - $dx Or $FG_x < 0 Then
    $i *= -1
    $j *= -1
    EndIf
    $FG_x += $j
    WEnd

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

    Func _Exit()
    _GDIPlus_BitmapDispose($hFGBitmap)
    _GDIPlus_GraphicsDispose($hFGBackbuffer)
    _GDIPlus_MatrixDispose($hMatrix)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    Exit
    EndFunc

    [/autoit]

    Im Anhang sind noch die Grafiken!

    Gruß,
    UEZ