GDI+ Graphic leeren

  • hey @ all,
    wie kann man in Gdi+ ein Graphic leeren, dass es quasi so ist, als ob es gerade erst neu erstellt wurde. mit _GDIPlus_GraphicsClear habe ich es nicht hinbekommen, da hier eine Farbe gesetzt wird, und ich will, dass das Graphic vollkommen leer und transparent ist.
    Wie geht das? ?(

    mfG
    Developer30

    "Je mehr Käse, desto mehr Löcher; je mehr Löcher, desto weniger Käse. Ergo: Je mehr Käse, desto weniger Käse. 8| "
    "Programmers never die: they just GOSUB without RETURN"
    "I tried to change the world but I couldn't find the source code."

  • Du kannst einfach eine neue Graphics anlegen. Die alte solltest du jedoch mit _GDIPlus_GraphicsRelease() oder so löschen, da du sonst ein Memoryleak erstellen könntest.
    Die Graphic komplett durchsichtig zu machen ist mit der normalen GDIPlus.au3 soviel ich weiß unmöglich, jedoch vielleicht mit der GDIP.au3 >>Gibts hier<<

    Meine Werke


    EasyScreen (teilweise Crocoframe): <EasyScreen>
    Spotify2Title: <Spotify2Title> (zur Info, dies ist KEIN Spotify-Downloader! Wer das dachte... :rofl: sowas gibts hier nicht :thumbdown: )

  • 0x00000000


    funktioniert bei mir nicht

    "Je mehr Käse, desto mehr Löcher; je mehr Löcher, desto weniger Käse. Ergo: Je mehr Käse, desto weniger Käse. 8| "
    "Programmers never die: they just GOSUB without RETURN"
    "I tried to change the world but I couldn't find the source code."

  • hm.. so ganz verstehen tu ich das jetzt nicht. also ist mir schon klar, dass ich nur male & quasi keine Transparenz drüber malen kann, weil Transparenz ja nicht sichtbar ist ^^
    wie müsste ich also nun folgendes Script ändern, damit der rote Kasten immer nur 1 mal auf dem Bild ist (und zugleich der Hintergrund sichtbar ist)?

    Spoiler anzeigen
    [autoit]

    #Include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    _GDIPlus_Startup()
    $bgcolor = 0x00000000
    $width = 625
    $height = 443
    $hGUI = GUICreate("Form", $width, $height)
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $GDI_Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
    GUISetState(@SW_SHOW)
    $hBG = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\bg.jpg")
    _GDIPlus_GraphicsDrawImage($GDI_Buffer, $hBG, 0, 0)
    $hPen = _GDIPlus_PenCreate(0xFFFF0000)
    While 1
    _GDIPlus_GraphicsDrawRect($GDI_Buffer, Random(0, $width), Random(0, $height), Random(0, 100), Random(0, 100),$hPen)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_ImageDispose($hBG)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $Bitmap, 0, 0, $width, $height)
    _GDIPlus_GraphicsClear($GDI_Buffer,$bgcolor)
    WEnd

    [/autoit]


    wie man an $bgcolor sieht, klappt 0x00000000 zu 0%...

    Edit: zum starten des Scripts, hinterlegt im @Scriptdir eine bg.jpg

    "Je mehr Käse, desto mehr Löcher; je mehr Löcher, desto weniger Käse. Ergo: Je mehr Käse, desto weniger Käse. 8| "
    "Programmers never die: they just GOSUB without RETURN"
    "I tried to change the world but I couldn't find the source code."

  • Mach es doch so:

    Spoiler anzeigen
    [autoit]

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

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

    $bgcolor = 0x00000000
    $width = 625
    $height = 443

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

    $hGUI = GUICreate("Form", $width, $height)
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $GDI_Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)

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

    $hBG = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\bg.jpg")
    $hPen = _GDIPlus_PenCreate(0xFFFF0000)

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

    AdlibRegister("_Draw", 100)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_ImageDispose($hBG)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($GDI_Buffer)
    _GDIPlus_BitmapDispose($Bitmap)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    WEnd

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

    Func _Draw()
    _GDIPlus_GraphicsDrawImage($GDI_Buffer, $hBG, 0, 0)
    _GDIPlus_GraphicsDrawRect($GDI_Buffer, Random(0, $width - 100), Random(0, $height - 100), Random(0, 100), Random(0, 100),$hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $Bitmap, 0, 0, $width, $height)
    EndFunc

    [/autoit]
  • name22:
    bei dem Beispiel handelt es sich nur um ein kleines Fenster --> kleines Hintergrundbild --> wenig zu laden.
    Wenn ich das später aber auf eine größere Fläche anwenden will, lädt es für den Hintergrund viel zu lange, weshalb ich den Hintergrund nur 1 mal malen möchte und danach mit einem Transparenten Buffer weiterarbeiten möchte.

    "Je mehr Käse, desto mehr Löcher; je mehr Löcher, desto weniger Käse. Ergo: Je mehr Käse, desto weniger Käse. 8| "
    "Programmers never die: they just GOSUB without RETURN"
    "I tried to change the world but I couldn't find the source code."

  • Dann begrenze den Bereich in dem das Hintergrundbild neu gezeichnet wird. Das geht so:

    Spoiler anzeigen
    [autoit]

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

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

    $width = 1200
    $height = 800

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

    $hGUI = GUICreate("Form", $width, $height)
    GUISetState()

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

    _GDIPlus_Startup()

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $GDI_Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)

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

    $hBG = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\bg.jpg")
    $hPen = _GDIPlus_PenCreate(0xFFFF0000)

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

    _GDIPlus_GraphicsDrawImageRect($GDI_Buffer, $hBG, 0, 0, $width, $height)

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

    AdlibRegister("_Draw", 500)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _GDIPlus_ImageDispose($hBG)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_GraphicsDispose($GDI_Buffer)
    _GDIPlus_BitmapDispose($Bitmap)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    WEnd

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

    Func _Draw()
    $iX = Random(0, $width - 100, 1)
    $iY = Random(0, $height - 100, 1)
    $iWidth_Rect = Random(0, 100, 1)
    $iHeight_Rect = Random(0, 100, 1)

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

    _GDIPlus_GraphicsSetClipRect($GDI_Buffer, $iX, $iY, $iWidth_Rect + 1, $iHeight_Rect + 1)
    _GDIPlus_GraphicsDrawRect($GDI_Buffer, $iX, $iY, $iWidth_Rect, $iHeight_Rect, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $Bitmap, 0, 0, $width, $height)
    _GDIPlus_GraphicsDrawImageRect($GDI_Buffer, $hBG, 0, 0, $width, $height)
    EndFunc

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_GraphicsSetClipRect
    ; Description ...: Updates the clipping region of a Graphics object to a region that is the combination of itself and a rectangle
    ; Syntax.........: _GDIPlus_GraphicsSetClipRect($hGraphics, $nX, $nY, $nWidth, $nHeight[, $iCombineMode = 0])
    ; Parameters ....: $hGraphics - Pointer to a Graphics object
    ; $nX - X coordinate of the upper-left corner of the rectangle
    ; $nY - Y coordinate of the upper-left corner of the rectangle
    ; $nWidth - Width of the rectangle
    ; $nHeight - Height of the rectangle
    ; $iCombineMode - Regions combination mode:
    ; |0 - The existing region is replaced by the new region
    ; |1 - The existing region is replaced by the intersection of itself and the new region
    ; |2 - The existing region is replaced by the union of itself and the new region
    ; |3 - The existing region is replaced by the result of performing an XOR on the two regions
    ; |4 - The existing region is replaced by the portion of itself that is outside of the new region
    ; |5 - The existing region is replaced by the portion of the new region that is outside of the existing region
    ; Return values .: Success - True
    ; Failure - False and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: None
    ; Related .......: None
    ; Link ..........; @@MsdnLink@@ GdipSetClipRect
    ; Example .......; No
    ; ===============================================================================================================================
    Func _GDIPlus_GraphicsSetClipRect($hGraphics, $nX, $nY, $nWidth, $nHeight, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRect", "hwnd", $hGraphics, "float", $nX, "float", $nY, "float", $nWidth, "float", $nHeight, "int", $iCombineMode)

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

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

    [/autoit]
  • ja. soweit hab ich auch schon gedacht. jetzt ist aber irgendwann der ganze $GDI_Buffer voll von dem Hintergrundbild & dann lädt der ja quasi wieder das ganze Hintergrundbild. Deshalb wollte ich dieses gerne dann resetten...

    "Je mehr Käse, desto mehr Löcher; je mehr Löcher, desto weniger Käse. Ergo: Je mehr Käse, desto weniger Käse. 8| "
    "Programmers never die: they just GOSUB without RETURN"
    "I tried to change the world but I couldn't find the source code."