Wie kann ich in einer GUI ein jpg Hintergrundbild einbinden, welches aber zu 50% transparent sein soll. Gleichzeit sollen aber die Texte und Buttons in der GUI nicht von der Transparenz betroffen sein, also zu 100% sichtbar. Leider konnte ich bis jetzt nur Hilfen finden, wo genau dies nicht der Fall war. Danke.
Hintergrundbild zu 50% transparent / Texte + Buttons sollen aber zu 100% angezeigt werden
-
- [ offen ]
-
timyboy -
1. April 2013 um 14:52 -
Geschlossen -
Erledigt
-
-
- Offizieller Beitrag
Warum soll das Bild halbtransparent sein, wenn es nichts gibt auf das die Transparenz wirkt? Dann kannst du doch einfach ein "blasses" Bild nehmen und hast denselben Effekt?
-
Meinst du sowas hier?
Spoiler anzeigen
[autoit]
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]
Global $hGUI = GUICreate("Test", 400, 300)
Global $iPicBG = GUICtrlCreatePic("", 0, 0, 400, 300)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $iInp = GUICtrlCreateInput("Coded by UEZ 2013", 50, 50, 300, 100)
Global $iBtnX = GUICtrlCreateButton("Exit", 350, 250, 40, 40)Global $iBGImage = _GDIPlus_BitmapCreateFromFile("c:\Program Files (x86)\AutoIt3\Examples\GUI\msoobe.jpg")
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_SendAlphaImageToControl($hGUI, $iBGImage, $iPicBG)
GUISetState()Do
[/autoit] [autoit][/autoit] [autoit]
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $iBtnX
GUIDelete()
_GDIPlus_BitmapDispose($iBGImage)
_GDIPlus_Shutdown()
Exit
EndSwitch
Until FalseFunc _GDIPlus_SendAlphaImageToControl($hGUI, $hImage, $iCtrl, $fAlpha = -0.33333) ;coded by UEZ 2013
[/autoit] [autoit][/autoit] [autoit]
Local $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate()
Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, $fAlpha)
Local $pColorMatrix = DllStructGetPtr($tColorMatrix)
_GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, $pColorMatrix)
Local $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage)
Local $aCtrl = ControlGetPos($hGUI, "", $iCtrl)
Local $iCtrlW = $aCtrl[2], $iCtrlH = $aCtrl[3]
Local $aRet = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iCtrlW, "int", $iCtrlH, "int", 0, "int", $GDIP_PXF32ARGB, "ptr", 0, "int*", 0)
Local $hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($aRet[6])
_GDIPlus_GraphicsDrawImageRectRectIA($hGfxCtxt, $hImage, 0, 0, $iW, $iH, 0, 0, $iCtrlW, $iCtrlH, $hAttribute_Alpha)
Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($aRet[6])
Local $hB = GUICtrlSendMsg($iCtrl, 0x0172, 0, $hHBITMAP)
If $hB Then _WinAPI_DeleteObject($hB)
_WinAPI_DeleteObject($hHBITMAP)
_GDIPlus_GraphicsDispose($hGfxCtxt)
_GDIPlus_BitmapDispose($aRet[6])
_GDIPlus_ImageAttributesDispose($hAttribute_Alpha)
EndFunc ;==>_GDIPlus_SendAlphaImageToControlFunc _GDIPlus_ColorMatrixCreate()
[/autoit] [autoit][/autoit] [autoit]
Return _GDIPlus_ColorMatrixCreateScale(1, 1, 1, 1)
EndFunc ;==>_GDIPlus_ColorMatrixCreateFunc _GDIPlus_ColorMatrixCreateScale($nRed, $nGreen, $nBlue, $nAlpha = 1)
[/autoit] [autoit][/autoit] [autoit]
Local $tCM, $tagGDIPCOLORMATRIX = "float m[25];"
$tCM = DllStructCreate($tagGDIPCOLORMATRIX)
DllStructSetData($tCM, "m", $nRed, 1)
DllStructSetData($tCM, "m", $nGreen, 7)
DllStructSetData($tCM, "m", $nBlue, 13)
DllStructSetData($tCM, "m", $nAlpha, 19)
DllStructSetData($tCM, "m", 1, 25)
Return $tCM
EndFunc ;==>_GDIPlus_ColorMatrixCreateScaleFunc _GDIPlus_ColorMatrixCreateTranslate($nRed, $nGreen, $nBlue, $nAlpha = 0)
[/autoit] [autoit][/autoit] [autoit]
Local $iI, $tCM, $aFactors[4] = [$nRed, $nGreen, $nBlue, $nAlpha]
$tCM = _GDIPlus_ColorMatrixCreate()
For $iI = 0 To 3
DllStructSetData($tCM, "m", $aFactors[$iI], 21 + $iI)
Next
Return $tCM
EndFunc ;==>_GDIPlus_ColorMatrixCreateTranslateFunc _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
[/autoit] [autoit][/autoit] [autoit]
Local $aResult = DllCall($ghGDIPDll, "int", "GdipDrawImageRectRect", "handle", $hGraphics, "handle", $hImage, "float", $nDstX, "float", $nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", $nSrcHeight, "int", $iUnit, "handle", $hImageAttributes, "int", 0, "int", 0)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectIAFunc _GDIPlus_ImageAttributesCreate()
[/autoit] [autoit][/autoit] [autoit]
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateImageAttributes", "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
Return $aResult[1]
EndFunc ;==>_GDIPlus_ImageAttributesCreateFunc _GDIPlus_ImageAttributesDispose($hImageAttributes)
[/autoit] [autoit][/autoit] [autoit]
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDisposeImageAttributes", "handle", $hImageAttributes)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_ImageAttributesDisposeFunc _GDIPlus_ImageAttributesSetColorMatrix($hImageAttributes, $iColorAdjustType = 0, $fEnable = False, $pClrMatrix = 0, $pGrayMatrix = 0, $iColorMatrixFlags = 0)
[/autoit]
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetImageAttributesColorMatrix", "handle", $hImageAttributes, "int", $iColorAdjustType, "int", $fEnable, "ptr", $pClrMatrix, "ptr", $pGrayMatrix, "int", $iColorMatrixFlags)
If @error Then Return SetError(@error, @extended, False)
Return $aResult[0] = 0
EndFunc ;==>_GDIPlus_ImageAttributesSetColorMatrixGruß,
UEZ -
Ja, meinte auch ein blasses Hintergrundbild, sorry. Leider geht das Beispiel nicht zu oeffnen...
-
Du musst den Pfad in Zeile 11 entsprechend anpassen!
Gruß,
UEZ -
Dein Spoiler geht leider nicht zu oeffnen im IE..
-
Dein Spoiler geht leider nicht zu oeffnen im IE..
Dann nimm einen anderen Browser!
Gruß,
UEZ