Gdi+ Grafik speichern

  • Hallo,

    ich habe folgendes Problem:

    1. Ich öffne ein Bild
    2, Ich zeichne darauf Text

    und dann sollte alles unter einem neuen Namen abgespeichert werden.
    Aber das klappt nicht!

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <gdiplus.au3>
    #include <ScreenCapture.au3>
    #include <WinAPI.au3>

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

    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    GUISetState(@SW_SHOW)

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

    _GDIPlus_Startup()

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

    $hgraphics = _GDIPlus_GraphicsCreateFromHWND($form1)
    ;$Bild1 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\bk.jpg")
    $Bild1 = _GDIPlus_BitmapCreateFromFile(FileOpenDialog("Bild auswählen", @UserProfileDir, "Bilder (*.*)"))

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

    _GDIPlus_GraphicsDrawImage($hgraphics,$Bild1,0,0)
    _GDIPlus_GraphicsDrawString($hGraphics, "Das ist ein Text", 50, 10,"Arial","50")

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

    _GDIPlus_ImageSaveToFile($hGraphics, @ScriptDir & "\GDIPlus.jpg")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

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


    Liebe Grüße
    Ilse ;)

    2 Mal editiert, zuletzt von Ilse (25. Juli 2012 um 14:28)

  • Hallo m-obi,

    hatte ich auch schon probiert.
    Dann wird einfach nur das Originalbild unter neuem Namen gespeichert.

    Aber es sollte ja mit dem Text abgespeichert werden.
    Und das geht nicht...

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <gdiplus.au3>
    #include <ScreenCapture.au3>
    #include <WinAPI.au3>

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

    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    GUISetState(@SW_SHOW)

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

    _GDIPlus_Startup()

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

    $hgraphics = _GDIPlus_GraphicsCreateFromHWND($form1)
    ;$Bild1 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\bk.jpg")
    $Bild1 = _GDIPlus_BitmapCreateFromFile(FileOpenDialog("Bild auswählen", @UserProfileDir, "Bilder (*.*)"))

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

    _GDIPlus_GraphicsDrawImage($hgraphics,$Bild1,0,0)
    _GDIPlus_GraphicsDrawString($hGraphics, "Das ist ein Text", 50, 10,"Arial","50")

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

    _GDIPlus_ImageSaveToFile($Bild1, @ScriptDir & "\GDIPlus.jpg")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

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

    :( Grüße Ilse

  • So?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <gdiplus.au3>
    #include <ScreenCapture.au3>
    #include <WinAPI.au3>

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

    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hgraphics = _GDIPlus_GraphicsCreateFromHWND($form1)
    ;$Bild1 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\bk.jpg")
    $hImage = _GDIPlus_BitmapCreateFromFile(FileOpenDialog("Bild auswählen", @UserProfileDir, "Bilder (*.*)"))
    $hgraphics2 = _GDIPlus_ImageGetGraphicsContext($hImage)

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

    _GDIPlus_GraphicsDrawImage($hgraphics, $hImage, 0, 0)
    _GDIPlus_GraphicsDrawString($hgraphics, "Das ist ein Text", 50, 10,"Arial","50")

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

    _GDIPlus_GraphicsDrawString($hgraphics2, "Das ist ein Text", 50, 10,"Arial","50")

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

    _GDIPlus_ImageSaveToFile($hImage, @DesktopDir & "\GDIPlus.jpg")

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

    _GDIPlus_Shutdown()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • Hallo m-obi,

    ja genau so. Super!
    Darf ich nochwas fragen?

    Gibt es wie.Z.B. wie bei Word die Möglichkeit
    in einer Combo alle Schriftarten und Größen anzuzeigen.
    So daß man vorher per Laufzeit das ändern kann?
    Kannst du mir da einen Tip geben?

    Ich habe nichts gefunden.

    ;) Ilse

  • Die Fonts sind doch alle Im Ordner bei Windows. Einfach den auslesen. Und die Größen einfach hochzählen. Übriegns kannst du bei Word auch Größen nehmen die in der Liste garnicht drinstehen, einfach eintippen ;)

  • Hallo,

    hab das mit den Fonts gefunden.
    Aber das einlesen mit GDI klappt noch nicht.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <gdiplus.au3>
    #include <ScreenCapture.au3>
    #include <WinAPI.au3>
    #include <misc.au3>
    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    GUISetState()

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

    $Test = _ChooseFont("","")
    _GDIPlus_Startup()

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

    $hgraphics = _GDIPlus_GraphicsCreateFromHWND($form1)
    ;$Bild1 = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\bk.jpg")
    $hImage = _GDIPlus_BitmapCreateFromFile(FileOpenDialog("Bild auswählen", @UserProfileDir, "Bilder (*.*)"))
    $hgraphics2 = _GDIPlus_ImageGetGraphicsContext($hImage)

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

    _GDIPlus_GraphicsDrawImage($hgraphics, $hImage, 0, 0)
    ;_GDIPlus_GraphicsDrawString($hgraphics, "Das ist ein Text", 50, 10,"Arial","50")
    _GDIPlus_GraphicsDrawString($hgraphics, $Test, 50, 10)

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

    ;_GDIPlus_GraphicsDrawString($hgraphics2, "Das ist ein Text", 50, 10,"Arial","50")

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

    _GDIPlus_GraphicsDrawString($hgraphics2, $Test, 50, 10)

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

    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\GDIPlus.jpg")

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

    _GDIPlus_Shutdown()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit]
  • Typisch Ilse. Schonmal geguckt was _ChooseFont zurückgibt??? Warum willst du $Test als String nehmen?

    Manchmal denk ich echt, dass du nicht mehr nachdenkst.

  • Hallo,

    ich hab's!

    @m-obi,
    hey, sei nicht immer so streng mit mir ;)
    Ich brauch halt manchmal etwas länger :(
    und danke für den erlösenden Tipp mit GDI

    chesstiger , $var
    super, dachte wirklich in Richtung Gui, einlesen...
    Dank euch!

    Liebe Grüße
    an alle ;) Ilse

  • Hallo,

    muß mich leider wieder melden.
    Nach langem probieren und testen bin ich einfach nicht mehr weitergekommen.

    1. Problem die Textfarbe
    Ich kann diese mit _Arraydisplay zwar ermitteln
    aber das Array bei _GDIPlus_GraphicsDrawString nicht eintragen

    2. Problem
    Ich wollte mit den Pfleiltasten eine neue Position für den Text bestimmen
    und dann abspeichern....
    Klappt leider auch nicht ... komme einfach nicht weiter

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <gdiplus.au3>
    #include <ScreenCapture.au3>
    #include <WinAPI.au3>
    #include <misc.au3>
    #include <array.au3>

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

    $x = 0
    $y = 0

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

    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    GUISetState()

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

    $Test = _ChooseFont()
    ;_ArrayDisplay($Test)
    $Text1 = "Das ist Text 1"
    $Text2 = "Das ist Text 2"
    $Text3 = "Das ist Text 3"

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

    _GDIPlus_Startup()

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

    $hgraphics = _GDIPlus_GraphicsCreateFromHWND($form1)
    $hImage = _GDIPlus_BitmapCreateFromFile(FileOpenDialog("Bild auswählen", @ScriptDir, "Bilder (*.jpg)"))
    $hgraphics2 = _GDIPlus_ImageGetGraphicsContext($hImage)

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

    _GDIPlus_GraphicsDrawImage($hgraphics, $hImage, 0, 0)

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

    _GDIPlus_GraphicsDrawString($hgraphics, $Text1, $x, $y,$Test[2],$Test[3]); hier habe ich XY Koordinaten
    _GDIPlus_GraphicsDrawString($hgraphics, $Text2, 80, 30,$Test[2],$Test[3])
    _GDIPlus_GraphicsDrawString($hgraphics, $Text3, 100, 70,$Test[2],$Test[3])
    $hgraphics2 = _GDIPlus_ImageGetGraphicsContext($hImage)

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

    ;ab hier wird gespeichert
    _GDIPlus_GraphicsDrawString($hgraphics, $Text1, $x, $y,$Test[2],$Test[3]); hier habe ich XY Koordinaten
    _GDIPlus_GraphicsDrawString($hgraphics, $Text2, 80, 30,$Test[2],$Test[3])
    _GDIPlus_GraphicsDrawString($hgraphics, $Text3, 100, 70,$Test[2],$Test[3])

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

    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Ilse.jpg")

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

    _GDIPlus_Shutdown()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    Select
    Case _IsPressed(25) ;Pfeil links
    $x -= 1
    Msgbox(0,$x,"gedrückt")
    Case _IsPressed(26)
    $y -= 1
    Case _IsPressed(27)
    $x += 1
    Case _IsPressed(28)
    $y += 1
    EndSelect
    ;_GDIPlus_GraphicsDrawString($hgraphics, $Text1, $x, $y,$Test[2],$Test[3])
    WEnd

    [/autoit]

    Bin noch am überlegen wie ich das am besten
    mit mehreren Texten lösen kann.
    Wäre schon mal toll wenn das mit den Farben und der Position klappen würde.


    Liebe Grüße
    Ilse ;)

  • 1. Verwende statt der jetzigen Funktion

    [autoit]

    _GDIPlus_GraphicsDrawStringEx

    [/autoit]

    da kannst du ein Brush Objekt beliebiger Farbe angeben.
    2. Was sollte da auch passieren? Bevor die Endlosschleife überhaupt anfängt und das erste Mal die Position verändert wird, ist doch schon längst alles gezeichnet und GDIPlus per GDIPlus_Shutdown wieder "deaktiviert". Du müsstest bei jeder Positionsveränderung alles neuzeichnen, speichern etc. und erst kurz vor Beenden des Scripts die verwendeten Ressourcen löschen und GDIPlus_Shutdown anwenden.

  • Hallo name22,

    huh...GDI Plus ist noch alles neu.
    Ja, logisch hatte ich übersehen.

    Ich komm mit
    _GDIPlus_GraphicsDrawStringEx

    irgendwie nicht weiter.
    Hab was aus der Hilfe gefunden
    aber das geht nicht.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <gdiplus.au3>
    #include <ScreenCapture.au3>
    #include <WinAPI.au3>
    #include <misc.au3>
    #include <array.au3>

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

    $x = 0
    $y = 0

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

    $Form1 = GUICreate("Form1", 625, 443, 192, 124)
    GUISetState()

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

    $Test = _ChooseFont()
    _ArrayDisplay($Test)
    $Text1 = "Das ist Text 1"
    $Text2 = "Das ist Text 2"
    $Text3 = "Das ist Text 3"

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

    _GDIPlus_Startup()

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

    $hBrush = _GDIPlus_BrushCreateSolid($Test[6]); Schriftfarbe von Array
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate($Test[2])
    $hFont = _GDIPlus_FontCreate($hFamily, $Test[3], 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 0, 0)
    ;$aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat)

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

    $hgraphics = _GDIPlus_GraphicsCreateFromHWND($Form1)
    $hImage = _GDIPlus_BitmapCreateFromFile(FileOpenDialog("Bild auswählen", @ScriptDir, "Bilder (*.jpg)"))
    $hgraphics2 = _GDIPlus_ImageGetGraphicsContext($hImage)

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

    _GDIPlus_GraphicsDrawImage($hgraphics, $hImage, 0, 0)

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

    _GDIPlus_GraphicsDrawStringEx($hgraphics, $Text1, $Test[2], 0, $hFormat, $hBrush) ;hier mit StringEx
    ;_GDIPlus_GraphicsDrawString($hgraphics, $Text1, $x, $y,$Test[2],$Test[3]); hier habe ich XY Koordinaten
    _GDIPlus_GraphicsDrawString($hgraphics, $Text2, 80, 30, $Test[2], $Test[3])
    _GDIPlus_GraphicsDrawString($hgraphics, $Text3, 100, 70, $Test[2], $Test[3])
    $hgraphics2 = _GDIPlus_ImageGetGraphicsContext($hImage)

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

    ;ab hier wird gespeichert
    _GDIPlus_GraphicsDrawString($hgraphics, $Text1, $x, $y, $Test[2], $Test[3]); hier habe ich XY Koordinaten
    _GDIPlus_GraphicsDrawString($hgraphics, $Text2, 80, 30, $Test[2], $Test[3])
    _GDIPlus_GraphicsDrawString($hgraphics, $Text3, 100, 70, $Test[2], $Test[3])

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

    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Ilse.jpg")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    Select
    Case _IsPressed(25) ;Pfeil links
    $x -= 1
    MsgBox(0, $x, "gedrückt")
    Case _IsPressed(26)
    $y -= 1
    Case _IsPressed(27)
    $x += 1
    Case _IsPressed(28)
    $y += 1
    EndSelect
    ;_GDIPlus_GraphicsDrawString($hgraphics, $Text1, $x, $y,$Test[2],$Test[3])
    WEnd

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

    _GDIPlus_Shutdown()

    [/autoit]
    Zitat

    Du müsstest bei jeder Positionsveränderung alles neuzeichnen, speichern etc

    Mir qualmt gerade so richtig der Kopf

    Grüße
    Ilse ?(

  • Anstatt _GDIPlus_GraphicsDrawStringEx, benutz lieber _GDIPlus_GraphicsDrawStringCustom.
    Der Umgang damit ist viel einfacher.

    Was das Verschieben angeht... Im Moment veränderst du nur die Variablen, in denen die Koordinaten gespeichert sind.
    Die Positionen der Strings verändern sich dadurch nicht, da sie bereits gezeichnet sind. Du musst also, nachdem du die Variablen verändert hast, alles löschen und mit den neuen Koordinaten neu zeichnen.
    Zum Löschen benutzt man _GDIPlus_GraphicsClear ($hGraphics). Neu zeichnen kannst du ja dann selbst...