Hintergrundbild zu 50% transparent / Texte + Buttons sollen aber zu 100% angezeigt werden

  • 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.

  • Meinst du sowas hier?

    Spoiler anzeigen
    [autoit]


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

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

    _GDIPlus_Startup()
    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)

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

    Global $iBGImage = _GDIPlus_BitmapCreateFromFile("c:\Program Files (x86)\AutoIt3\Examples\GUI\msoobe.jpg")
    _GDIPlus_SendAlphaImageToControl($hGUI, $iBGImage, $iPicBG)
    GUISetState()

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

    Do
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE, $iBtnX
    GUIDelete()
    _GDIPlus_BitmapDispose($iBGImage)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
    Until False

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

    Func _GDIPlus_SendAlphaImageToControl($hGUI, $hImage, $iCtrl, $fAlpha = -0.33333) ;coded by UEZ 2013
    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_SendAlphaImageToControl

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

    Func _GDIPlus_ColorMatrixCreate()
    Return _GDIPlus_ColorMatrixCreateScale(1, 1, 1, 1)
    EndFunc ;==>_GDIPlus_ColorMatrixCreate

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

    Func _GDIPlus_ColorMatrixCreateScale($nRed, $nGreen, $nBlue, $nAlpha = 1)
    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_ColorMatrixCreateScale

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

    Func _GDIPlus_ColorMatrixCreateTranslate($nRed, $nGreen, $nBlue, $nAlpha = 0)
    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_ColorMatrixCreateTranslate

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

    Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
    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_GraphicsDrawImageRectRectIA

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

    Func _GDIPlus_ImageAttributesCreate()
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateImageAttributes", "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[1]
    EndFunc ;==>_GDIPlus_ImageAttributesCreate

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

    Func _GDIPlus_ImageAttributesDispose($hImageAttributes)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipDisposeImageAttributes", "handle", $hImageAttributes)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
    EndFunc ;==>_GDIPlus_ImageAttributesDispose

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

    Func _GDIPlus_ImageAttributesSetColorMatrix($hImageAttributes, $iColorAdjustType = 0, $fEnable = False, $pClrMatrix = 0, $pGrayMatrix = 0, $iColorMatrixFlags = 0)
    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_ImageAttributesSetColorMatrix

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (1. April 2013 um 22:24)

  • Du musst den Pfad in Zeile 11 entsprechend anpassen!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯