GDI+ SaveImageToFile How to?!

  • hab mal zum verständnis / test ein kleines script gemacht welches mir eine zufällig erstellte kurve anzeigen soll und dann als bild abspeichern

    jedoch ist das gespeicherte bild immer nur komplett schwarz ??! egal ob als bmp / jpg / png gespeichert

    die test.bmp ist einfach nur ein weißer hintergrund, kann man auch weglassen ;P

    hoffe jemand bekommt es hin oder erkennt den fehler direkt :)

    mfg


    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    dim $aPoints[41][2],$hBitmap,$hGraphic,$hImage
    $apoints[0][0] = 40
    for $i = 10 to 400 step 10
    $apoints[$i/10][0] = $i
    $apoints[$i/10][1] = random(10,90,1)
    next

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

    $hGUI = GUICreate("GDI+", 407, 108)
    GUISetState()
    _GDIPlus_Startup ()
    $hBitmap = _GDIPlus_BitmapCreateFromFile("test.bmp") ; einfach nur zum test ein weißer hintergrund
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hBitmap, 0, 0)
    draw_dots()
    $hbit = _GDIPlus_BitmapCreateFromGraphics(400, 100, $hGraphic)
    _GDIPlus_ImageSaveToFile($hbit, @hour&@min&@SEC&".bmp") ; speichert aber nur ein komplett schwarzes bild....... -_-
    _GDIPlus_ShutDown ()

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

    while 1
    sleep(60)
    WEnd

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

    func draw_dots()
    _GDIPlus_GraphicsDrawCurve ($hGraphic, $aPoints)
    EndFunc

    [/autoit]
  • Mit GUI brauchst du glaubich die Funktion:
    _GDIPlus_Save_to_Image

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    dim $aPoints[41][2],$hBitmap,$hGraphic,$hImage
    $apoints[0][0] = 40
    for $i = 10 to 400 step 10
    $apoints[$i/10][0] = $i
    $apoints[$i/10][1] = random(10,90,1)
    next

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

    $hGUI = GUICreate("GDI+", 407, 108)
    GUISetState()
    _GDIPlus_Startup ()
    $hBitmap = _GDIPlus_BitmapCreateFromFile("test.bmp") ; einfach nur zum test ein weißer hintergrund
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    _GDIPlus_GraphicsDrawImage ($hGraphic, $hBitmap, 0, 0)
    draw_dots()
    $hbit = _GDIPlus_BitmapCreateFromGraphics(400, 100, $hGraphic)
    ;~ _GDIPlus_ImageSaveToFile($hbit, @hour&@min&@SEC&".bmp") ; speichert aber nur ein komplett schwarzes bild....... -_-
    _GDIPlus_Save_to_Image (@hour&@min&@SEC&".png",$hGUI)
    _GDIPlus_ShutDown()

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

    while GUIGetMsg()<>-3
    sleep(60)
    WEnd

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

    func draw_dots()
    _GDIPlus_GraphicsDrawCurve ($hGraphic, $aPoints)
    EndFunc

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

    Func _GDIPlus_Save_to_Image($file, $hWnd, $CLSID = "PNG", $w = 0, $h = 0)
    Local $hDC, $memBmp, $memDC, $hImage, $size, $sCLSID
    If $file <> "" Or $hWnd <> "" Then
    If $w = 0 Or $h = 0 Then
    $size = WinGetClientSize($hWnd)
    $w = $size[0]
    $h = $size[1]
    EndIf
    $hDC = _WinAPI_GetDC($hWnd)
    $memDC = _WinAPI_CreateCompatibleDC($hDC)
    $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
    _WinAPI_SelectObject ($memDC, $memBmp)
    _WinAPI_BitBlt($memDC, 0, 0, $w, $h, $hDC, 0, 0, 0x00CC0020) ; 0x00CC0020 = $SRCCOPY
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp)
    $sCLSID = _GDIPlus_EncodersGetCLSID ($CLSID)
    _GDIPlus_ImageSaveToFileEx ($hImage, $file, $sCLSID)
    If @error Then
    Return SetError(1, 0, 0)
    Else
    Return SetError(0, 0, 0)
    EndIf
    _GDIPlus_ImageDispose ($hImage)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($memDC)
    _WinAPI_DeleteObject ($memBmp)
    Else
    Return SetError(1, 0, 0)
    EndIf
    EndFunc

    [/autoit]

    Funktioniert aufjedenfall so ;)