GDI+ auf GUI & Datei

  • Nachdem ich mich als GDI+-DAU mit GDI+ beschäftige (muss), stehe ich vor einem Problem.

    Im Prinzip soll ein Hintergrund (Bild oder Farbe), ein (wegem dem Hintergrund transparenter) Vordergrund und ein Text gezeichnet und auf eine extra GUI als "Vorschaubild" gezeichnet sowie als Bilddatei abgespeichert werden. Das Problem ist aber, dass die letzten 2 Schritte ("Vorschaubild" + speichern) nicht funktionieren :/

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>

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

    Dim $File_Background = '' ;Pfad zur Hintergrunddatei
    Dim $File_Transparent = '' ;Pfad für Transparente Datei für den Vordergrund

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

    Dim $Draw_BackgroundFile = True ;Hintergrundbild oder nur Farbe zeichnen

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

    $drawGUI = GUICreate('GUI zum zeichnen', 1280, 720)
    GUISetState() ;im fertigen Script ist die GUI dann nicht sichtbar ;)
    $hGui = GUICreate('sichtbare GUI', 500, 300)
    GUISetState()
    _GDIPlus_Startup()

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

    $hgraphics = _GDIPlus_GraphicsCreateFromHWND($drawGUI)

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

    $hgraphics_hGui = _GDIPlus_GraphicsCreateFromHWND($hGui)

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

    $Image_Picture = _GDIPlus_ImageLoadFromFile($File_Transparent)
    $Image_Background = _GDIPlus_ImageLoadFromFile($File_Background)
    $hBrush = _GDIPlus_BrushCreateSolid(0xff00ff00)

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

    If $Draw_BackgroundFile = True Then
    _GDIPlus_GraphicsDrawImageRect($hgraphics, $Image_Background, 0, 0, 1280, 720)
    Else
    _GDIPlus_GraphicsFillRect($hgraphics,0,0,1280,720,$hBrush)
    EndIf

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

    _GDIPlus_GraphicsDrawImageRect($hgraphics,$Image_Picture,0,0,1280,720)
    _GDIPlus_GraphicsDrawString($hgraphics, 'Test String',10,10,'Arial',100)

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

    _GDIPlus_GraphicsDrawImageRect($hgraphics_hGui, $hgraphics, 50,50,400,400/16*9) ; nun alles auf die sichtbare GUI zeichnen
    $hBitmap=_GDIPlus_BitmapCreateFromGraphics(1280,720,$hgraphics)
    _GDIPlus_ImageSaveToFile($hBitmap,@ScriptDir&'\Test.jpg')

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

    _GDIPlus_GraphicsDispose($Image_Picture)
    _GDIPlus_GraphicsDispose($Image_Background)
    _GDIPlus_GraphicsDispose($hgraphics)
    _GDIPlus_GraphicsDispose($hgraphics_hGui)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_Shutdown()

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

    Sleep(2500)

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Du musst ein Bitmap statt eines GUI verwenden, um das Bild zu erstellen:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    Dim $File_Background = '' ;Pfad zur Hintergrunddatei
    Dim $File_Transparent = '' ;Pfad für Transparente Datei für den Vordergrund

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

    Dim $Draw_BackgroundFile = True ;Hintergrundbild oder nur Farbe zeichnen

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

    $hGui = GUICreate('sichtbare GUI', 500, 300)
    GUISetState()
    _GDIPlus_Startup()

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

    $hDrawBitmap = _GDIPlus_BitmapCreateFromScan0(1280, 720)
    $hDrawContext = _GDIPlus_ImageGetGraphicsContext($hDrawBitmap)

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

    $hgraphics_hGui = _GDIPlus_GraphicsCreateFromHWND($hGui)

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

    $Image_Picture = _GDIPlus_ImageLoadFromFile($File_Transparent)
    $Image_Background = _GDIPlus_ImageLoadFromFile($File_Background)
    $hBrush = _GDIPlus_BrushCreateSolid(0xff00ff00)

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

    If $Draw_BackgroundFile = True Then
    _GDIPlus_GraphicsDrawImageRect($hDrawContext, $Image_Background, 0, 0, 1280, 720)
    Else
    _GDIPlus_GraphicsFillRect($hDrawContext,0,0,1280,720,$hBrush)
    EndIf

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

    _GDIPlus_GraphicsDrawImageRect($hDrawContext,$Image_Picture,0,0,1280,720)
    _GDIPlus_GraphicsDrawString($hDrawContext, 'Test String',10,10,'Arial',100)

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

    _GDIPlus_GraphicsDrawImageRect($hgraphics_hGui, $hDrawBitmap, 50,50,400,400/16*9) ; nun alles auf die sichtbare GUI zeichnen
    _GDIPlus_ImageSaveToFile($hDrawBitmap,@ScriptDir&'\Test.jpg')

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

    _GDIPlus_GraphicsDispose($Image_Picture)
    _GDIPlus_GraphicsDispose($Image_Background)
    _GDIPlus_GraphicsDispose($hDrawContext)
    _GDIPlus_BitmapDispose($hDrawBitmap)
    _GDIPlus_BitmapDispose($Image_Background)
    _GDIPlus_BitmapDispose($Image_Picture)
    _GDIPlus_GraphicsDispose($hgraphics_hGui)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_Shutdown()

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

    Sleep(2500)

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_BitmapCreateFromScan0
    ; Description ...: Creates a Bitmap object based on an array of bytes along with size and format information
    ; Syntax.........: _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight[, $iStride = 0[, $iPixelFormat = 0x0026200A[, $pScan0 = 0]]])
    ; Parameters ....: $iWidth - The bitmap width, in pixels
    ; $iHeight - The bitmap height, in pixels
    ; $iStride - Integer that specifies the byte offset between the beginning of one scan line and the next. This
    ; +is usually (but not necessarily) the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
    ; +multiplied by the width of the bitmap. The value passed to this parameter must be a multiple of four
    ; $iPixelFormat - Specifies the format of the pixel data. Can be one of the following:
    ; |$GDIP_PXF01INDEXED - 1 bpp, indexed
    ; |$GDIP_PXF04INDEXED - 4 bpp, indexed
    ; |$GDIP_PXF08INDEXED - 8 bpp, indexed
    ; |$GDIP_PXF16GRAYSCALE - 16 bpp, grayscale
    ; |$GDIP_PXF16RGB555 - 16 bpp; 5 bits for each RGB
    ; |$GDIP_PXF16RGB565 - 16 bpp; 5 bits red, 6 bits green, and 5 bits blue
    ; |$GDIP_PXF16ARGB1555 - 16 bpp; 1 bit for alpha and 5 bits for each RGB component
    ; |$GDIP_PXF24RGB - 24 bpp; 8 bits for each RGB
    ; |$GDIP_PXF32RGB - 32 bpp; 8 bits for each RGB. No alpha.
    ; |$GDIP_PXF32ARGB - 32 bpp; 8 bits for each RGB and alpha
    ; |$GDIP_PXF32PARGB - 32 bpp; 8 bits for each RGB and alpha, pre-mulitiplied
    ; $pScan0 - Pointer to an array of bytes that contains the pixel data. The caller is responsible for
    ; +allocating and freeing the block of memory pointed to by this parameter.
    ; Return values .: Success - Returns a handle to a new Bitmap object
    ; Failure - 0 and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources
    ; Related .......: _GDIPlus_ImageDispose
    ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromScan0
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", $iStride, "int", $iPixelFormat, "ptr", $pScan0, "int*", 0)

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

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[6]
    EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

    [/autoit]

    E