GDI-Stapel-Bearbeitung

  • Hallo Leute,

    ich habe mich nie mit den GDI-Funktionen auseinandergesetzt und daher hoffe ich auf Hilfe eurerseits.
    Hier meine Problem:

    - ich habe viele Jpg's (Maße identisch), die ich in einer For-Schleife abarbeite (vorher GDI-Start, nachher GDI-Beendigung)

    - das Bild soll nach unten mit weißem Hintergrund erweitert werden (Breite gleich, Höhe + X)
    - es sollen zwei verschiedene Text-Labels gezeichnet werden (Größe und Farbe variabel)
    - es soll ein Quadrat gezeichnet werden (Farbe variabel)
    - es soll möglichst verlustfrei (wahlweise eins davon: Tiff, Png, hohe Jpg-Qualität oder Bitmap) gespeichert werden

    So sollte es nachher grob ausschauen:

    Spoiler anzeigen

    Mir reicht der grobe Aufbau mit den nötigen Befehlen.
    Ich möchte mich im Voraus dafür entschuldigen, dass es sehr nach "Macht-mir-bitte-mal" klingt!

    Dankeschön :)

    Einmal editiert, zuletzt von AndyTR (16. Februar 2014 um 18:08)

  • Wie wäre es damit?

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    Global $sPath_Image = @ScriptDir & "\Input.jpg"
    Global $sPath_Save = @ScriptDir & "\Output.png"

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

    _GDIPlus_Startup()

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

    OnAutoItExitRegister("_Shutdown")
    _AddInfoBar($sPath_Save, $sPath_Image, "Text2666699", "AutoIt Rocks!", 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 10, 12, 40)

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

    Func _AddInfoBar($sSavePath, $sImagePath, $sString1, $sString2, $iColor_Square, $iColor1 = 0xFF000000, $iColor2 = 0xFF000000, $iSize1 = 12, $iSize2 = 12, $iInfoBar_Height = 40)
    Local $hImage, $hBitmap, $hGraphics, $iImage_Width, $iImage_Height, $hBrush_White, $hBrush_Square, $hBrush_String1, $hBrush_String2
    Local $hPen_Square, $hFontFamily, $hFont1, $hFont2, $hStringFormat, $tRect_Layout1, $tRect_Layout2

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

    $hImage = _GDIPlus_ImageLoadFromFile($sImagePath)

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

    $iImage_Width = _GDIPlus_ImageGetWidth($hImage)
    $iImage_Height = _GDIPlus_ImageGetHeight($hImage)

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

    $hBitmap = _GDIPlus_BitmapCreateFromScan0($iImage_Width, $iImage_Height + $iInfoBar_Height)
    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, 5)

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

    $hBrush_White = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    $hBrush_Square = _GDIPlus_BrushCreateSolid($iColor_Square)
    $hPen_Square = _GDIPlus_PenCreate(0xFF000000, 1)
    $hBrush_String1 = _GDIPlus_BrushCreateSolid($iColor1)
    $hBrush_String2 = _GDIPlus_BrushCreateSolid($iColor2)
    $hFontFamily = _GDIPlus_FontFamilyCreate("Segoe UI")
    $hFont1 = _GDIPlus_FontCreate($hFontFamily, $iSize1)
    $hFont2 = _GDIPlus_FontCreate($hFontFamily, $iSize2)

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

    $tRect_Layout1 = _GDIPlus_RectFCreate($iImage_Width * 0.05, $iImage_Height, $iImage_Width * 0.35, $iInfoBar_Height)
    $tRect_Layout2 = _GDIPlus_RectFCreate($iImage_Width * 0.40, $iImage_Height, $iImage_Width * 0.35, $iInfoBar_Height)
    $hStringFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hStringFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hStringFormat, 1)

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

    _GDIPlus_GraphicsClear($hGraphics)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iImage_Width, $iImage_Height)
    _GDIPlus_GraphicsFillRect($hGraphics, 0, $iImage_Height, $iImage_Width, $iInfoBar_Height, $hBrush_White)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString1, $hFont1, $tRect_Layout1, $hStringFormat, $hBrush_String1)
    _GDIPlus_GraphicsDrawStringEx($hGraphics, $sString2, $hFont2, $tRect_Layout2, $hStringFormat, $hBrush_String2)
    _GDIPlus_GraphicsFillRect($hGraphics, $iImage_Width * 0.8, $iImage_Height + $iInfoBar_Height * 0.3, $iInfoBar_Height * 0.4, $iInfoBar_Height * 0.4, $hBrush_Square)
    _GDIPlus_GraphicsDrawRect($hGraphics, $iImage_Width * 0.8, $iImage_Height + $iInfoBar_Height * 0.3, $iInfoBar_Height * 0.4, $iInfoBar_Height * 0.4, $hPen_Square)

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

    _GDIPlus_ImageSaveToFile($hBitmap, $sSavePath)

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

    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BrushDispose($hBrush_Square)
    _GDIPlus_BrushDispose($hBrush_String1)
    _GDIPlus_BrushDispose($hBrush_String2)
    _GDIPlus_BrushDispose($hBrush_White)
    _GDIPlus_PenDispose($hPen_Square)
    _GDIPlus_FontDispose($hFont1)
    _GDIPlus_FontDispose($hFont2)
    _GDIPlus_FontFamilyDispose($hFontFamily)
    _GDIPlus_StringFormatDispose($hStringFormat)

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

    Return True
    EndFunc

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

    Func _Shutdown()
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit]
  • name22, du hast jetzt nicht ernsthaft genau das gleiche wie ich fabriziert :D

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    _Img('BildVorher.png', 'BildNachher.png', 'Text1', 0xFF804020, 'Text2', 0xFF204080)
    If @error Then ConsoleWrite('!ERROR: ' & @error & @CRLF)

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

    Func _Img($sPathSrc, $sPathDst, $sLabel1, $iCol1, $sLabel2, $iCol2)
    Local $iBorderH = 0.2 ; Anzahl Pixel (0 -> inf) ODER Höhe in % (1 = 100% = Borderhöhe = Bildhöhe, 0.1 = 10%, usw)
    Local $bBorderPercent = $iBorderH < 1 ; Automatisch True, wenn die Höhe kleiner als 1 ist.
    Local $iBkCol = 0xFFFFFFFF ; Hintergundfarbe
    Local $sFontFamily = 'Arial'
    Local $iFontSizePx = $iBorderH/2
    Local $bBold = True
    Local $iBoxSizePx = $iBorderH/2
    Local $fPenWidth = $iBorderH/50
    Local $iPenCol = 0xFF000000
    _GDIPlus_Startup()
    Local $iError
    Local $hImg = _GDIPlus_ImageLoadFromFile($sPathSrc)
    If @error Then
    $iError = @error
    _GDIPlus_ImageDispose($hImg)
    _GDIPlus_Shutdown()
    Return SetError($iError)
    EndIf
    Local $iW = _GDIPlus_ImageGetWidth($hImg)
    Local $iH = _GDIPlus_ImageGetHeight($hImg)
    If $bBorderPercent Then
    $iBorderH *= $iH
    $iFontSizePx *= $iH
    $iBoxSizePx *= $iH
    $fPenWidth *= $iH
    If $fPenWidth < 1 Then $fPenWidth = 1
    EndIf
    $iH += $iBorderH
    Local $hBuf = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBuf)
    _GDIPlus_GraphicsClear($hGfx, $iBkCol)
    _GDIPlus_GraphicsDrawImageRectRect($hGfx, $hImg, 0, 0, $iW, $iH, 0, 0, $iW, $iH) ; Man könnte auch nur DrawImage oder nur DrawImageRect nutzen, in sehr seltenen Fällen geschehen hier aber spukhafte Sachen...
    _GDIPlus_GraphicsSetTextRenderingHint($hGfx, 3) ; schönere Schrift
    Local $hFam = _GDIPlus_FontFamilyCreate($sFontFamily)
    Local $hFon = _GDIPlus_FontCreate($hFam, $iFontSizePx, $bBold ? 1 : 0, 2)
    Local $hFor = _GDIPlus_StringFormatCreate()
    Local $iD = ($iBorderH - $iBoxSizePx) / 2 ; Abstand der Box zum Rand
    Local $hPen = _GDIPlus_PenCreate($iPenCol, $fPenWidth)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 2)
    _GDIPlus_GraphicsDrawRect($hGfx, $iW - $iD - $iBoxSizePx, $iH - $iD - $iBoxSizePx, $iBoxSizePx, $iBoxSizePx, $hPen)
    _GDIPlus_StringFormatSetAlign($hFor, 1)
    _GDIPlus_StringFormatSetLineAlign($hFor, 1)
    Local $tRect = _GDIPlus_RectFCreate(0, $iH - $iBorderH, $iW/3, $iBorderH)
    Local $hBru = _GDIPlus_BrushCreateSolid($iCol1)
    _GDIPlus_GraphicsDrawStringEx($hGfx, $sLabel1, $hFon, $tRect, $hFor, $hBru)
    _GDIPlus_BrushSetSolidColor($hBru, $iCol2)
    $tRect = _GDIPlus_RectFCreate($iW/3, $iH - $iBorderH, $iW/3, $iBorderH) ; darf überschrieben werden, da Struct
    _GDIPlus_GraphicsDrawStringEx($hGfx, $sLabel2, $hFon, $tRect, $hFor, $hBru)
    _GDIPlus_ImageSaveToFile($hBuf, $sPathDst)
    _GDIPlus_BrushDispose($hBru)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_StringFormatDispose($hFor)
    _GDIPlus_FontDispose($hFon)
    _GDIPlus_FontFamilyDispose($hFam)
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_BitmapDispose($hBuf)
    _GDIPlus_ImageDispose($hImg)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit]

    Damit hast du 2 funktionierende Lösungen :D

    lg
    M

  • Ich weiß nicht welches Script du jetzt meinst. Die Zeilenangabe macht für mich in beiden Fällen nicht viel Sinn.
    Aber wir haben ja beide praktisch das selbe Vorgehen. Du musst entweder für einen String ein separates StringFormat Objekt erstellen und bei DrawStringEx angeben oder das StringFormat Objekt, das beide verwenden, vor dem zweiten Aufruf von DrawStringEx verändern. In beiden Fällen verwendest du die Funktion _GDIPlus_StringFormatSetAlign mit dem Parameter 2. In der Hilfe kannst du nachlesen welcher Parameter was macht.