GDI+ Bitmap speichern...

  • Hallo,
    mal 2 Beispielscripte, ich hab gerade nen Gehirnkrampf und komme nicht weiter....
    Wie bekomme ich die die BITMAPS (innerhalb des Fensters) gespeichert...

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GDIPlus.au3>

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

    Opt('MustDeclareVars', 1)

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

    _Main()

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

    Func _Main()
    Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout

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

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    $hWnd = WinGetHandle("GDI+")
    GUISetState()

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

    ; Draw a string
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    $hBrush = _GDIPlus_BrushCreateSolid (0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate ()
    $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    $hFont = _GDIPlus_FontCreate ($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate (140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx ($hGraphic, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)

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

    ;*********************Bitmap soll gespeichert werden********************

    [/autoit] [autoit][/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]


    oder hier....

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

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

    Opt('MustDeclareVars', 1)

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

    _GDIPlus_Startup()

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

    local $hfile_Source = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\web\wallpaper\Tulpen.jpg")
    local $hfile_dest = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\web\wallpaper\Mondkrater.jpg")
    local $iX1 = 300;_GDIPlus_ImageGetWidth($hSource1)
    local $iY1 = 400;_GDIPlus_ImageGetHeight($hSource1)
    local $iX2 = 300;_GDIPlus_ImageGetWidth($hSource2)
    local $iY2 = 400;_GDIPlus_ImageGetHeight($hSource2)

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

    ;****************GUI DEST*******************
    local $hGui_dest = GUICreate("DEST", $iX1 , $iY1)
    local $hPic_dest = GUICtrlCreatePic('', 0,0, $iX1 , $iY1)
    local $hWnd_dest = WinGetHandle($hGui_dest)
    GUISetState(@sw_show,$hgui_dest)

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

    local $hGraphic_dest = _GDIPlus_GraphicsCreateFromHWND($hWnd_dest)
    local $hDestination_dest = _GDIPlus_BitmapCreateFromGraphics($iX1, $iY1, $hGraphic_dest)
    local $hGraphiccontext_dest = _GDIPlus_ImageGetGraphicsContext($hDestination_dest)
    _GDIPlus_GraphicsDrawImage($hGraphiccontext_dest, $hfile_dest, 0, 0) ;ziel in context schreiben
    _GDIPlus_GraphicsDrawImage($hGraphic_dest, $hfile_dest, 0, 0); ziel ist fenster

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

    ;****************GUI source*******************
    local $hGui_source = GUICreate("SOURCE", $iX2 , $iY2,10,10)
    local $hPic_source = GUICtrlCreatePic('', 0,0, $iX2 , $iY2)
    local $hWnd_source = WinGetHandle($hGui_source)
    GUISetState(@sw_show,$hgui_source)

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

    local $hGraphic_source = _GDIPlus_GraphicsCreateFromHWND($hWnd_source)
    local $hDestination_source = _GDIPlus_BitmapCreateFromGraphics($iX2, $iY2, $hGraphic_source)
    local $hGraphiccontext_source = _GDIPlus_ImageGetGraphicsContext($hDestination_source)
    _GDIPlus_GraphicsDrawImage($hGraphiccontext_source, $hfile_Source, 0, 0) ;wenn man das bild in den Context schreibt, kann man es speichern
    _GDIPlus_GraphicsDrawImage($hGraphic_source, $hfile_Source, 0, 0) ;bild in das Fenster zeichnen

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

    ;*************BITBLT*****************
    local $verfahren=$mergepaint
    local $hdc_dest = _WinAPI_GetDC($hgui_dest)
    local $hdc_source = _WinAPI_GetDC($hgui_source)
    sleep(1000)
    _WinAPI_BitBlt($hDC_dest, 0, 0, $ix1, $iy1, $hDC_source, 0,0, $verfahren)

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

    ;**************BITMAP aus Fenster DEST soll gespeichert werden**************

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

    Do
    Until GUIGetMsg() = -3

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

    _GDIPlus_Shutdown()

    [/autoit]

    thx vorab
    Andy

    EDIT/ soll nicht per screencopy, sondern "direkt aus dem Context gespeichert werden

  • Am besten direkt ins Bitmap zeichnen:

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    #include <GDIPlus.au3>

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

    Opt('MustDeclareVars', 1)

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

    _Main()

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

    Func _Main()
    Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hImage, $hGraphic_hWnd

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

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    $hWnd = WinGetHandle("GDI+")
    GUISetState()

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

    ; Draw a string
    _GDIPlus_Startup()
    $hGraphic_hWnd = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hImage = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphic_hWnd)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
    $hFormat = _GDIPlus_StringFormatCreate()
    $hFamily = _GDIPlus_FontFamilyCreate("Arial")
    $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
    $tLayout = _GDIPlus_RectFCreate(140, 110, 100, 20)
    _GDIPlus_GraphicsDrawStringEx($hGraphic, "Hello world", $hFont, $tLayout, $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawImage($hGraphic_hWnd, $hImage, 0, 0)

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

    ;*********************Bitmap soll gespeichert werden********************

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

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

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

    _GDIPlus_ImageSaveToFile($hImage, "Test.bmp")
    _GDIPlus_ImageDispose($hImage)

    [/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]

    bzw.: direkt DC speichern:

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

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

    Opt('MustDeclareVars', 1)

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

    _GDIPlus_Startup()

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

    local $hfile_Source = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\web\wallpaper\Tulpen.jpg")
    local $hfile_dest = _GDIPlus_ImageLoadFromFile(@WindowsDir & "\web\wallpaper\Mondkrater.jpg")
    local $iX1 = 300;_GDIPlus_ImageGetWidth($hSource1)
    local $iY1 = 400;_GDIPlus_ImageGetHeight($hSource1)
    local $iX2 = 300;_GDIPlus_ImageGetWidth($hSource2)
    local $iY2 = 400;_GDIPlus_ImageGetHeight($hSource2)

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

    ;****************GUI DEST*******************
    local $hGui_dest = GUICreate("DEST", $iX1 , $iY1)
    local $hPic_dest = GUICtrlCreatePic('', 0,0, $iX1 , $iY1)
    local $hWnd_dest = WinGetHandle($hGui_dest)
    GUISetState(@sw_show,$hgui_dest)

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

    local $hGraphic_dest = _GDIPlus_GraphicsCreateFromHWND($hWnd_dest)
    local $hDestination_dest = _GDIPlus_BitmapCreateFromGraphics($iX1, $iY1, $hGraphic_dest)
    local $hGraphiccontext_dest = _GDIPlus_ImageGetGraphicsContext($hDestination_dest)
    _GDIPlus_GraphicsDrawImage($hGraphiccontext_dest, $hfile_dest, 0, 0) ;ziel in context schreiben
    _GDIPlus_GraphicsDrawImage($hGraphic_dest, $hfile_dest, 0, 0); ziel ist fenster

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

    ;****************GUI source*******************
    local $hGui_source = GUICreate("SOURCE", $iX2 , $iY2,10,10)
    local $hPic_source = GUICtrlCreatePic('', 0,0, $iX2 , $iY2)
    local $hWnd_source = WinGetHandle($hGui_source)
    GUISetState(@sw_show,$hgui_source)

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

    local $hGraphic_source = _GDIPlus_GraphicsCreateFromHWND($hWnd_source)
    local $hDestination_source = _GDIPlus_BitmapCreateFromGraphics($iX2, $iY2, $hGraphic_source)
    local $hGraphiccontext_source = _GDIPlus_ImageGetGraphicsContext($hDestination_source)
    _GDIPlus_GraphicsDrawImage($hGraphiccontext_source, $hfile_Source, 0, 0) ;wenn man das bild in den Context schreibt, kann man es speichern
    _GDIPlus_GraphicsDrawImage($hGraphic_source, $hfile_Source, 0, 0) ;bild in das Fenster zeichnen

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

    ;*************BITBLT*****************
    local $verfahren=$mergepaint
    local $hdc_dest = _WinAPI_GetDC($hgui_dest)
    local $hdc_source = _WinAPI_GetDC($hgui_source)
    sleep(1000)
    _WinAPI_BitBlt($hDC_dest, 0, 0, $ix1, $iy1, $hDC_source, 0,0, $verfahren)

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

    ;**************BITMAP aus Fenster DEST soll gespeichert werden**************

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

    Local $hBitmap=_WinAPI_CreateCompatibleBitmap($hdc_dest, $iX1, $iY1)
    Local $hdc_mem=_WinAPI_CreateCompatibleDC($hdc_dest)
    _WinAPI_SelectObject($hdc_mem, $hBitmap)
    _WinAPI_BitBlt($hdc_mem, 0, 0, $iX1, $iY1, $hDC_dest, 0,0, $SRCCOPY)

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

    Local $hImage=_GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
    _GDIPlus_ImageSaveToFile($hImage, "Test1.bmp")

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

    Do
    Until GUIGetMsg() = -3

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

    _GDIPlus_Shutdown()

    [/autoit]
  • thx vielmals...
    aber:^^
    Man bekommt beim Beispiel1 den "richtigen" Fensterinhalt in die Datei gespeichert, auch wenn GuiSetState() ausgeklammert ist. Das verstehe ich, man speichert ja direkt die Bitmap.

    Im 2. Beispiel wird, wenn ich die Bildbearbeitung im "Hintergrund" laufen lasse, nur eine Bildschirmcopy gespeichert. Das hat wohl den Grund, daß die devicecontexte die Bitmapdaten an der Position der (unsichtbaren) GUI auf dem Bildschirm kopieren. Wie müsste man das Script ändern, daß sowohl bei "eingeschalteter" GUI, als auch im Hintergrund die richtigen Bitmaps gespeichert werden?