UDF um Bilder Transparent zu machen

  • Schon länger wollte ich etwas machen, um Bilder halbtransparent anzuzeigen.
    Jetzt ist es fertig:2 Funktionen
    Eine arbeitet mit einer DLL (auch von mir), die andere nur mit Autoit

    UDF+Beispiel

    Spoiler anzeigen
    [autoit]


    #include-once
    #include <DLLshow.au3>
    #include <GDIP.au3>
    ;#test
    _GDIPlus_Startup()
    $bmp=_GDIPlus_BitmapCreateFromFile("zzz.bmp")
    $alpha=100
    $bmp=_BmpTEllipse($bmp,$alpha)
    _GDIPlus_Imageshow($bmp)
    _GDIPlus_BitmapDispose($bmp)
    $bmp=_GDIPlus_BitmapCreateFromFile("zzz.bmp")
    $bmp=_TBmpFromBmp($bmp,$alpha,0,10,-1,10)
    $bmp=_TBmpFromBmp($bmp,$alpha,0,30,-1,10)
    $bmp=_TBmpFromBmp($bmp,$alpha,0,50,-1,10)
    $bmp=_TBmpFromBmp($bmp,$alpha,0,70,-1,10)
    $bmp=_TBmpFromBmp($bmp,$alpha,0,90,-1,10)
    $bmp=_TBmpFromBmp($bmp,$alpha,10,0,10,-1)
    $bmp=_TBmpFromBmp($bmp,$alpha,30,0,10,-1)
    $bmp=_TBmpFromBmp($bmp,$alpha,50,0,10,-1)
    $bmp=_TBmpFromBmp($bmp,$alpha,70,0,10,-1)
    $bmp=_TBmpFromBmp($bmp,$alpha,90,0,10,-1)
    $bmp=_TBmpFromBmp($bmp,$alpha,110,0,10,-1)
    _GDIPlus_Imageshow($bmp)
    _GDIPlus_BitmapDispose($bmp)
    $bmp=_GDIPlus_BitmapCreateFromFile("zzz.bmp")
    $bmp=_TBmpFromBmpDll($bmp,$alpha)
    _GDIPlus_Imageshow($bmp)
    _GDIPlus_BitmapDispose($bmp)
    _GDIPlus_Shutdown()
    ;#

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

    Func _BmpTEllipse($bmp,$alpha=100,$px=0,$py=0,$width=-1,$height=-1)
    If $bmp=0 Then Return 0
    Local $w,$h
    $w=_GDIPlus_ImageGetWidth($bmp)-1
    $h=_GDIPlus_ImageGetHeight($bmp)-1
    If $width=-1 Then $width=$w
    If $height=-1 Then $height=$h
    Local $tmpbmp=_GDIPlus_BitmapCloneArea($bmp,0,0,$w,$h)
    Local $color,$farben[$w+1][$h+1]
    For $x=0 To $w
    For $y=0 To $h
    $farben[$x][$y]="0x"&Hex(_gdiplus_Bitmapgetpixel($bmp,$x,$y))
    Next
    Next
    For $b=0 to 255
    For $g=0 to 255
    For $r=0 to 255
    $isin=0
    For $x=0 To $w
    For $y=0 To $h
    If StringRight($farben[$x][$y],6)=Hex($r,2)&Hex($g,2)&Hex($b,2) Then $isin=1
    Next
    Next
    If $isin=0 Then
    $color="0xFF"&Hex($r,2)&Hex($g,2)&Hex($b,2)
    ExitLoop 3
    EndIf
    Next
    Next
    Next
    Local $gra=_GDIPlus_ImageGetGraphicsContext($bmp)
    Local $brush=_GDIPlus_BrushCreateSolid($color)
    _GDIPlus_GraphicsFillEllipse($gra,$px,$py,$width,$height,$brush)
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_GraphicsDispose($gra)
    For $x=0 To $w
    For $y=0 To $h
    $hex="0x"&Hex(_gdiplus_Bitmapgetpixel($bmp,$x,$y))
    If $hex=$color Then
    $ncolor="0x"&Hex($alpha,2)&StringRight(Hex(_gdiplus_Bitmapgetpixel($tmpbmp,$x,$y)),6)
    _gdiplus_Bitmapsetpixel($bmp,$x,$y,$ncolor)
    EndIf
    Next
    Next
    _GDIPlus_BitmapDispose($tmpbmp)
    Return $bmp
    EndFunc

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

    Func _TBmpFromBmp($bmp,$alpha=100,$px=0,$py=0,$width=-1,$height=-1)
    If $bmp=0 Then Return 0
    Local $w=_GDIPlus_ImageGetWidth($bmp)
    Local $h=_GDIPlus_ImageGetHeight($bmp)
    If $height<>-1 Then $h=$height
    If $width<>-1 Then $w=$width
    For $x=$px To $w+$px
    For $y=$py To $h+$py
    $pixel=_gdiplus_Bitmapgetpixel($bmp,$x,$y)
    $hex=Hex($pixel)
    $npixel="0x"&Hex($alpha,2)&StringRight($hex,6)
    _gdiplus_Bitmapsetpixel($bmp,$x,$y,$npixel)
    Next
    Next
    Return $bmp
    EndFunc

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

    Func _TBmpFromBmpDll($bmp,$alpha=100,$altesweg=1)
    If $bmp=0 Then Return 0
    Local $dat=@TempDir&"\tmp.bmp"
    Local $clsid=_GDIPlus_EncodersGetCLSID("BMP")
    _GDIPlus_ImageSaveToFileEx($bmp,$dat,$clsid)
    If $altesweg=1 Then _GDIPlus_BitmapDispose($bmp)
    DllCall("transbitmapx86.dll","none","_BmpToTBmp","str",$dat,"int",$alpha,"str",$dat)
    Local $tbmp=_GDIPlus_BitmapCreateFromFile($dat)
    Return $tbmp
    EndFunc

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

    Func Diashow($img,$mswechsel=1000,$titel="",$x=-1,$y=-1)
    If Not IsArray($img) Then Return -1
    Local $frames=UBound($img,1)-1
    Local $frame=0
    Local $timer=TimerInit()
    Local $skill
    Local $wx,$wy
    If $x=-1 Then
    $x=_GDIPlus_ImageGetWidth($img[0])
    EndIf
    If $x>@DesktopWidth Then $x=@DesktopWidth
    If $y=-1 Then
    $y=_GDIPlus_ImageGetHeight($img[0])
    EndIf
    if $y>@DesktopHeight-50 Then $y=@DesktopHeight-50
    $wx=$x
    $wy=$y
    Local $gui=GUICreate($titel,$x,$y,Default,Default,BitOR(0x00C00000,0x00080000)) ;bitor($WS_CAPTION,$WS_SYSMENU)
    GUISetState(@SW_SHOW,$gui)
    Local $gra=_GDIPlus_GraphicsCreateFromHWND($gui)
    Local $buffer=_GDIPlus_BitmapCreateFromGraphics($wx,$wy,$gra)
    Local $backgra=_GDIPlus_ImageGetGraphicsContext($buffer)
    _GDIPlus_GraphicsSetSmoothingMode($backgra,2)
    While GUIGetMsg()<>-3 ;$GUI_EVENT_CLOSE
    _WinAPI_RedrawWindow($gui, "", "", 1280) ;$RDW_UPDATENOW + $RDW_FRAME
    If TimerDiff($timer)-$skill>=$mswechsel Then
    $skill=TimerDiff($timer)
    $frame+=1
    If $frame>$frames Then $frame=0
    EndIf
    _GDIPlus_GraphicsClear($backgra)
    _GDIPlus_GraphicsDrawImageRect($backgra,$img[$frame],0,0,$wx,$wy)
    _GDIPlus_GraphicsDrawImageRect($gra,$buffer,0,0,$wx,$wy)
    Sleep(10)
    WEnd
    _GDIPlus_GraphicsDispose($backgra)
    _GDIPlus_BitmapDispose($buffer)
    _GDIPlus_GraphicsDispose($gra)
    GUIDelete($gui)
    Return 1
    EndFunc

    [/autoit]

    Der Inhalt kann nicht angezeigt werden, da er nicht mehr verfügbar ist.

    Der Inhalt kann nicht angezeigt werden, da er nicht mehr verfügbar ist.
    Der Inhalt kann nicht angezeigt werden, da er nicht mehr verfügbar ist.

    Edit: Neues Beispiel und neue Autoitfunktion
    Edit: Neue Funktion: Transparente Ellipse im Bild