[GDI+]Bilddrehung via Matrizen

  • Guten Morgen, ich arbeite momentan an einem Schulprojekt und muss dafür ein Bild drehen. Ich sitze da jetzt schon 3 1/2 Stunden dran und habe langsam keine Zeit mehr.
    Mein Problem ist, dass das Bild auf der Stelle gedreht werden soll. Der Mittelpunkt der Matrix liegt aber nicht auf dem gedrehten BIld, sodass sich der Pfeil um einen bestimmten Punkt dreht. GIbt es eine Möglichkeit den Mittelpunkt der Rotation in die Mitte des BIldes zu legen?

    Spoiler anzeigen
    [autoit]

    Func _ImageRotate($hImgZiel, $hImgQuelle, $degree)
    $hGraphicsDest = _GDIPlus_ImageGetGraphicsContext($hImgZiel)
    $hMatrixRotate = _GDIPlus_MatrixCreate()
    $iWidth = _GDIPlus_ImageGetWidth($hImgQuelle)
    $iHeight = _GDIPlus_ImageGetHeight($hImgQuelle)
    _GDIPlus_MatrixRotate($hMatrixRotate, $degree, "false")
    _GDIPlus_GraphicsSetTransform($hGraphicsDest, $hMatrixRotate)
    _GDIPlus_GraphicsDrawImage($hGraphicsDest, $hImgQuelle, 0, 0)
    _GDIPlus_MatrixDispose($hMatrixRotate)
    EndFunc ;=>_ImageRotate() (Quick and Dirty)

    [/autoit]

    €dit: Der Sinn: Ein Pfeil soll mit einer beliebigen Drehung auf ein anderes Bild an eine beliebige Koordinate gemalt werden.

    2 Mal editiert, zuletzt von @night@ (28. September 2011 um 09:18)

  • Du musst zuerst die Matrix zum Drehmittelpunkt verschieben, dann Drehen und dann wieder zurückverschieben

    [autoit]

    _GDIPlus_MatrixTranslate($hMatrix, $iWidth / 2, $iHeight / 2)
    _GDIPlus_MatrixRotate($hMatrix, $iAngle)
    _GDIPlus_MatrixTranslate($hMatrix, -$iWidth / 2, -$iHeight / 2)

    [/autoit]

    E

  • Boah, danke dir. Nach mehr als 4 Stunden endlich das gewünschte Erbenis. Hatte noch ein paar andere Probleme aber trotzdem vielen Dank ;)

    Spoiler anzeigen
    [autoit]

    Func _ImageRotate($hImgZiel, $hImgQuelle, $degree, $nX, $nY)
    $hGraphicsZiel = _GDIPlus_ImageGetGraphicsContext($hImgZiel)
    $hMatrixRotate = _GDIPlus_MatrixCreate()
    $iWidth = _GDIPlus_ImageGetWidth($hImgQuelle)
    $iHeight = _GDIPlus_ImageGetHeight($hImgQuelle)
    _GDIPLUS_MatrixTranslate($hMatrixRotate, $nX + $iWidth/2, $nY + $iHeight/2)
    _GDIPlus_MatrixRotate($hMatrixRotate, $degree)
    _GDIPLUS_MatrixTranslate($hMatrixRotate, -$iWidth/2 - $nX, -$iHeight/2 - $nY)
    _GDIPlus_GraphicsSetTransform($hGraphicsZiel, $hMatrixRotate)
    _GDIPlus_GraphicsDrawImage($hGraphicsZiel, $hImgQuelle, $nX, $nY)
    _GDIPlus_MatrixDispose($hMatrixRotate)
    EndFunc ;=>_ImageRotate()

    [/autoit]