GDI+ : 1 Bild + 2 Bild = ???

  • So, ich möchte ein Funktion bei der man eine Zahl angibt und rauskommen tut ein fertiges Bild auf dem man die Zahlen sieht. Jedoch sollen die Zahlen so aussehen: (siehe Anhang)

    Die eineselnen Zahlenbilder sind in dieser Array:

    [autoit]

    $number[0-9]

    [/autoit]


    gespeichert.
    Mein Versuch:

    [autoit]

    func SetLive($lnsrw)
    _GDIPlus_Startup()

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

    ;Checkt die Länge des Strings:
    $lsn = StringLen ( $lnsrw )

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

    ;erzeugt eine Art Hintergrund
    $za1 = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle("Number"))
    $zah1 = _GDIPlus_ImageGetGraphicsContext($za1)

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

    ;Zerlegt den String
    for $i = 0 to $lsn step 1
    $zx = StringMid ( $lnsrw, $i,1 )
    $zax = $number[$zx]
    $weite=_GDIPlus_ImageGetHeight($zax)
    $hohe=_GDIPlus_ImageGetWidth($zax)
    _GDIPlus_GraphicsDrawImageRect( $zah1, $zax, $i*$weite, 0, $weite, $hohe)
    next

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

    Return $za1

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

    EndFunc

    [/autoit]


    Jedoch hab ich Probleme mit den Funktionen umzugehen. Deshalb brauche ich ein Entwurf von euch...Ich sitze nun schon 3 Stunden dran und nun reichts :S

  • Damit der Text wie in dem Bild aussieht, benötigst du ein Font!

    Hier ein GDI+ Text Beispiel:

    Spoiler anzeigen
    [autoit]


    ;coded by UEZ
    #include <GuiConstantsEx.au3>
    #include <GDIPlus.au3>
    #include <Array.au3>

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

    Opt('MustDeclareVars', 1)

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

    Global $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout
    Global $x, $y, $w, $h
    Global $sString = "Hello world"
    Global $width = 400
    Global $heigh = 40
    ; Create GUI
    $hWnd = GUICreate("GDI+", $width, $heigh)
    GUISetState()

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

    _Main()

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

    Func _Main()

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

    ; Draw a string
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    $hBrush = _GDIPlus_BrushCreateSolid (0xFF00007F)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)
    Measure($sString)
    $tLayout = _GDIPlus_RectFCreate (($width - $w) / 2, ($heigh - $h) / 2, 0, 0)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, $sString, $hFont, $tLayout, $hFormat, $hBrush)

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

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

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

    ; Clean up resources
    _GDIPlus_FontDispose ($hFont)
    _GDIPlus_FontFamilyDispose ($hFamily)
    _GDIPlus_StringFormatDispose ($hFormat)
    _GDIPlus_BrushDispose ($hBrush)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

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

    EndFunc ;==>_Main

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

    Func Measure($text)
    Local $hBuffer = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    Local $hBrush = _GDIPlus_BrushCreateSolid (0xFF00007F)
    Local $hFormat = _GDIPlus_StringFormatCreate ()
    Local $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    Local $hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)
    Local $tLayout = _GDIPlus_RectFCreate (0, 0, 0, 0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString ($hBuffer, $sString, $hFont, $tLayout, $hFormat)
    $x = DllStructGetData($aInfo[0],1)
    $y = DllStructGetData($aInfo[0],2)
    $w = DllStructGetData($aInfo[0],3)
    $h = DllStructGetData($aInfo[0],4)
    ConsoleWrite("x: " & $x & @CRLF & "y: " & $y & @CRLF & "w: " & $w & @CRLF & "h: " & $h & @CRLF)
    EndFunc

    [/autoit]

    Willst du ein Font laden und in GDI+ benutzen, so schaue doch mal hier vorbei: http://www.autoitscript.com/forum/index.php?showtopic=94679&view=findpost&p=680168&hl=&fromsearch=1

    Gruß,
    UEZ

    PS: ist ein älteres Beispiel!

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (4. Dezember 2009 um 23:08)

  • Aber das Beispiel aus der Hilfe ist wohl besser und einfacher:

    Spoiler anzeigen
    [autoit]


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

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

    $hWnd = GUICreate("GDI+ Example", 500, 300)
    GUISetState()

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

    _GDIPlus_Startup()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    _GDIPlus_GraphicsClear($hGraphics, 0xFFFFFFFF)

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

    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 36)
    $hLayout = _GDIPlus_RectFCreate(0, 150 - 36, 500, 300)
    $hStringFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hStringFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, "0 1 2 3 4 5 6 7 8 9", $hFont, $hLayout, $hStringFormat, $hBrush)

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

    Do
    $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

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

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_StringFormatDispose($hStringFormat)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯