[GDI+] Rect auf Bmp Tranzparent setzten

  • Hey.

    Ich Suche eine Möglichkeit ein Rect auf einem Bitmap schneller Tranzparent zu setzten als mit dieser Funktion, welche shadow gecodet hat :

    [autoit]

    Func _MakeTransRect($bmp,$x,$y,$w,$h)
    Local $s
    Local $d=_GDIPlus_BitmapLockBits($bmp,$x,$y,$w,$h,$GDIP_ILMWRITE,$GDIP_PXF32ARGB)
    Local $height=DllStructGetData($d,"Height")
    Local $size=$w*4,$scan0=DllStructGetData($d,"Scan0"),$stride=DllStructGetData($d,"Stride")
    For $xx=0 To $height-1
    $s=DllStructCreate("byte["&$size&"]",$scan0+$xx*$stride)
    For $xxx=1 To $size
    DllStructSetData($s,1,0,$xxx)
    Next
    Next
    _GDIPlus_BitmapUnlockBits($bmp,$d)
    Return $bmp
    EndFunc

    [/autoit]

    mfg

    Das finden von Rechtschreibfehlern muss sofort und unverzüglich dem Autor gemeldet werden. Das eigennützige Verwenden dieser Rechtschreibfehler ist strengstens untersagt und kann mit Freiheitsenzug bestraft werden.

    Einmal editiert, zuletzt von Darter (5. Februar 2011 um 18:28)

  • Du kannst das mit ein paar Funktionen aus der GDIP.au3 erreichen. Das dürfte um einiges schneller sein, als die Pixel einzeln transparent zu setzen.

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

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

    $iX_Clip = 50
    $iY_Clip = 50
    $iWidth_Clip = 200
    $iHeight_Clip = 200

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

    $sPathImage = FileOpenDialog("Bild öffnen", @ScriptDir, "Bilder (*.jpg;*.bmp;*.png)")
    If @error Then Exit

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

    _GDIPlus_Startup()

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

    $hImage = _GDIPlus_ImageLoadFromFile($sPathImage)
    $iWidth = _GDIPlus_ImageGetWidth($hImage)
    $iHeight = _GDIPlus_ImageGetHeight($hImage)

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

    $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) ;Erzeugt eine neue leere Bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)

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

    _GDIPlus_GraphicsSetClipRect($hGraphic, $iX_Clip, $iY_Clip, $iWidth_Clip, $iHeight_Clip, 3) ;Setzt eine Begrenzung für Zeichenfläche.

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

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)

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

    _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Test.png")

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

    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()

    [/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] [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]
  • Hey.

    Thx erstmal, werde ihch gleich mal ausprobieren.

    Das finden von Rechtschreibfehlern muss sofort und unverzüglich dem Autor gemeldet werden. Das eigennützige Verwenden dieser Rechtschreibfehler ist strengstens untersagt und kann mit Freiheitsenzug bestraft werden.

  • Wenn ich dich richtig verstanden habe, willst du ein Rechteck auf ein Bild zeichnen, welches transparent ist:

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>

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

    $iX_Clip = 50
    $iY_Clip = 50
    $iWidth_Clip = 200
    $iHeight_Clip = 200

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

    $sPathImage = FileOpenDialog("Bild öffnen", @ScriptDir, "Bilder (*.jpg;*.bmp;*.png)")
    If @error Then Exit

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

    _GDIPlus_Startup()

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

    $hImage = _GDIPlus_ImageLoadFromFile($sPathImage)
    $iWidth = _GDIPlus_ImageGetWidth($hImage)
    $iHeight = _GDIPlus_ImageGetHeight($hImage)

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

    $hBitmap = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) ;Erzeugt eine neue leere Bitmap
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    $hBrush = _GDIPlus_BrushCreateSolid(0x60FFFFFF)

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

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)
    _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $iWidth / 2 ,$iHeight / 2, $hBrush)

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

    _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\Test.jpg")

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

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()

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

    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]

    Wenn nicht, dann habe ich dich nicht richtig verstanden.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯


  • Nicht ganz.

    Ich habe ein Bitmap, in diesem Bitmap soll ein bestimmter bereich, schneller alss mit der oben geposteten funktion, tranzparent gesetzt werden, sodass dahinterliegende ctrls wieder sichtbar werden ;)

    EDIT: jetzt bitte nicht schrieben, das geht auch mit Child guis, das weiß ich xD

    Das finden von Rechtschreibfehlern muss sofort und unverzüglich dem Autor gemeldet werden. Das eigennützige Verwenden dieser Rechtschreibfehler ist strengstens untersagt und kann mit Freiheitsenzug bestraft werden.

  • Warum hast du Controls, worauf du eine Bitmap legen willst? Ich verstehe nicht ganz, was du erreichen willst. Eigentlicht ist das umgekehrt oder?

    Kann aber auch an meinem Alter liegen...

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Dann ist das Script aus meinem ersten Beitrag das was du brauchst? Oder funktioniert es nicht wie du es dir vorstellst?
    UEZ Vielleich will er das als eine Art Hintegrundbild in einer GUI. ?( Sozusagen die GDI+ Variante von GUICtrlCreatePic... :S

  • hey.
    @ name22 ich habe es noch nicht ausprobiert aber das dürfte es sein.

    Naja ich zeihcne mehrere Sachen auf die Gui, welche natürlich ach mal neu gezeichnet werden, sobald dies geschiet verschinden die ctrl hinter dem gezeichneten.
    Ich verwende eig. buttons usw. aber input felder wollte ich eben die standart Gui ctrls nutzen ;)

    mfg

    Das finden von Rechtschreibfehlern muss sofort und unverzüglich dem Autor gemeldet werden. Das eigennützige Verwenden dieser Rechtschreibfehler ist strengstens untersagt und kann mit Freiheitsenzug bestraft werden.

  • Zitat von name22

    UEZ Vielleich will er das als eine Art Hintegrundbild in einer GUI. ?( Sozusagen die GDI+ Variante von GUICtrlCreatePic... :S

    Richtig. (Ich kenn seinen Quellcode)

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

  • Ok habs nun ausprobiert.
    Klappt super :)

    mfg

    Das finden von Rechtschreibfehlern muss sofort und unverzüglich dem Autor gemeldet werden. Das eigennützige Verwenden dieser Rechtschreibfehler ist strengstens untersagt und kann mit Freiheitsenzug bestraft werden.

  • Ja da hatte ich schonmal reingeschnuppert, ist aber ziehmlich viel code.
    Hab die zu gebrauchende stelle nicht gefunden.
    Wie machst du es denn, evtl kannst du den code schipsel dann hier posten.

    Wobei die Lösung von Name22 natürlich recht gut funktioniert ;)

    Das finden von Rechtschreibfehlern muss sofort und unverzüglich dem Autor gemeldet werden. Das eigennützige Verwenden dieser Rechtschreibfehler ist strengstens untersagt und kann mit Freiheitsenzug bestraft werden.

  • Nach der GUI und GDI+ Initialisierung:

    Spoiler anzeigen
    [autoit]


    ...
    Global Const $GW_CHILD = 5
    Global Const $GW_HWNDNEXT = 2
    Global $hRegion = _GDIPlus_RegionCreateFromRect(_GDIPlus_RectFCreate(0, 0, $width, $height))
    Global $hChild = _WinAPI_GetWindow($hGUI, $GW_CHILD)
    Global $aRect
    Do
    $aRect = ControlGetPos($hChild, "", 0)
    _GDIPlus_RegionCombineRect($hRegion, _GDIPlus_RectFCreate($aRect[0], $aRect[1], $aRect[2], $aRect[3]), 3)
    $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    Until Not $hChild
    _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion)
    _GDIPlus_RegionDispose($hRegion)
    ...

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

    Func _GDIPlus_GraphicsSetClipRegion($hGraphics, $hRegion, $iCombineMode = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetClipRegion", "hwnd", $hGraphics, "hwnd", $hRegion, "int", $iCombineMode)

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

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

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

    Func _GDIPlus_RegionCreateFromRect($tRectF)
    Local $pRectF, $aResult

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

    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateRegionRect", "ptr", $pRectF, "int*", 0)

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

    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[2]
    EndFunc

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

    Func _GDIPlus_RegionCombineRect($hRegion, $tRectF, $iCombineMode = 2)
    Local $pRectF, $aResult

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

    $pRectF = DllStructGetPtr($tRectF)
    $aResult = DllCall($ghGDIPDll, "uint", "GdipCombineRegionRect", "hwnd", $hRegion, "ptr", $pRectF, "int", $iCombineMode)

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

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

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

    Func _GDIPlus_RegionDispose($hRegion)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDeleteRegion", "hwnd", $hRegion)

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

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

    [/autoit]

    Funktioniert mit Group Controls leider nicht!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯