GDI+ - Bild erstellen und Pixel zeichnen

  • Hier ein kleines Beispiel:

    Spoiler anzeigen

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>


    Global Const $width = 100
    Global Const $height = 100
    Global $graphics, $backbuffer, $bitmap, $Pen, $i, $pi_div_180 = 4 * ATan(1) / 180
    Global $radius_x = ($width * 0.5) * 0.90, $radius_y = ($height * 0.5) * 0.90
    Global $title = "GDI+ Beispiel"

    Opt("GUIOnEventMode", 1)
    $hwnd = GUICreate($title, $width, $height, -1, -1, BitOR($WS_SYSMENU,$WS_DLGFRAME,$WS_POPUP))
    GUISetOnEvent($GUI_EVENT_CLOSE, "close")
    GUISetState()

    _GDIPlus_Startup()
    $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    $pen = _GDIPlus_PenCreate(0xFFFFFFFF, 2)

    Do
    _GDIPlus_GraphicsClear($backbuffer)
    _GDIPlus_GraphicsDrawEllipse($backbuffer, $width * 0.5 + Cos($i * $pi_div_180) * $radius_x, $height * 0.5 + Sin($i * $pi_div_180) * $radius_y, 1, 1, $Pen)
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    $i += 1
    If $i = 360 Then $i = 0
    Sleep(10)
    Until False

    Func close()
    _GDIPlus_PenDispose($pen)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    WinClose($hwnd)
    Exit
    EndFunc

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Hi,

    Danke UEZ für deinen Beispiel. Ok jetzt hab ich es einigermaßen verstanden. Eine Frage noch. Wie kann ich das Bild speichern?

    Der Befehl _GDIPlus_ImageSaveToFile klingt reichlich verdächtig ;)

    Beispiel mit dem Script oben:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <GDIPlus.au3>

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

    Global Const $width = 100
    Global Const $height = 100
    Global $graphics, $backbuffer, $bitmap, $Pen, $i, $pi_div_180 = 4 * ATan(1) / 180
    Global $radius_x = ($width * 0.5) * 0.90, $radius_y = ($height * 0.5) * 0.90
    Global $title = "GDI+ Beispiel",$go=0

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

    Opt("GUIOnEventMode", 1)
    $hwnd = GUICreate($title, $width, $height, -1, -1, BitOR($WS_SYSMENU,$WS_DLGFRAME,$WS_POPUP))
    GUISetOnEvent($GUI_EVENT_CLOSE, "close")
    GUISetState()

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

    _GDIPlus_Startup()
    $graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    $pen = _GDIPlus_PenCreate(0xFFFFFFFF, 2)

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

    While $go<>200
    _GDIPlus_GraphicsClear($backbuffer)
    _GDIPlus_GraphicsDrawEllipse($backbuffer, $width * 0.5 + Cos($i * $pi_div_180) * $radius_x, $height * 0.5 + Sin($i * $pi_div_180) * $radius_y, 1, 1, $Pen)
    _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
    $i += 1
    $go+= 1
    If $i = 360 Then $i = 0
    Sleep(10)
    WEnd
    _GDIPlus_ImageSaveToFile($bitmap, @ScriptDir&"\Gespeichert.jpg")
    close()

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

    Func close()
    _GDIPlus_PenDispose($pen)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    WinClose($hwnd)
    Exit
    EndFunc

    [/autoit]