UDF > WinAPIEx > GDI > BitMaps >


_WinAPI_AlphaBlend

Affiche des bitmaps qui ont des pixels transparents ou semi-transparents

#include <WinAPIGdi.au3>
_WinAPI_AlphaBlend ( $hDestDC, $iXDest, $iYDest, $iWidthDest, $iHeightDest, $hSrcDC, $iXSrc, $iYSrc, $iWidthSrc, $iHeightSrc, $iAlpha [, $bAlpha = False] )

Param�tres

$hDestDC Handle du contexte de p�riph�rique de destination.
$iXDest La coordonn�e x, en unit�s logiques, du coin sup�rieur gauche du rectangle de destination.
$iYDest La coordonn�e y, en unit�s logiques, du coin sup�rieur gauche du rectangle de destination.
$iWidthDest La largeur, en unit�s logiques, du rectangle de destination.
$iHeightDest La hauteur, en unit�s logiques, du rectangle de destination.
$hSrcDC Handle du contexte de p�riph�rique source.
$iXSrc La coordonn�e, en unit�s logiques, du coin sup�rieur gauche du rectangle source.
$iYSrc La coordonn�e y, en unit�s logiques, du coin sup�rieur gauche du rectangle source.
$iWidthSrc La largeur, en unit�s logiques, du rectangle source.
$iHeightSrc La hauteur, en unit�s logiques, du rectangle source.
$iAlpha La valeur de transparence alpha � utiliser sur l'ensemble du bitmap source.
Cette valeur est combin�e avec des valeurs alpha par pixel dans le bitmap source.
Si vous d�finissez $iAlpha � ​​0, il est suppos� que votre image est transparente.
D�finissez la valeur de $iAlpha � 255 (opaque) lorsque vous souhaitez utiliser uniquement les valeurs alpha par pixel.
$bAlpha [optionnel] Sp�cifie s'il faut utiliser un canal alpha � partir du bitmap source, les valeurs valides sont:
    True - Utilise le canal alpha (c'est-�-dire alpha par pixel).
        Notez que les API utilisent un alpha pr�multipli�e, ce qui signifie que les valeurs des canaux rouge, vert et bleu dans l'image bitmap doit �tre pr�multipli�es avec la valeur du canal alpha.
        Par exemple, si la valeur du canal alpha est x, les canaux rouge, vert et bleu sont � multiplier par x et divis�s par 255 avant l'appel.
    False - Ne pas utiliser le canal alpha (par d�faut).

Valeur de retour

Succ�s: Retourne True.
�chec: Retourne False.

Remarques

Si le rectangle source et le rectangle destination ne sont pas de la m�me taille, le bitmap source est �tir� en fonction du rectangle destination.
Si la fonction _WinAPI_SetStretchBltMode() est utilis�e, la valeur du mode d'�tirement est automatiquement convertie en $COLORONCOLOR pour cette fonction (c'est-�-dire $BLACKONWHITE, $WHITEONBLACK, et $HALFTONE sont chang�s en $COLORONCOLOR).

Si les bitmaps destination et source n'ont pas le m�me format de couleurs, la fonction _WinAPI_AlphaBlend() convertit le bitmap source pour correspondre au bitmap destination.

Voir aussi

Consultez GdiAlphaBlend dans la librairie MSDN.

Exemple

#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIGdiDC.au3>
#include <WinAPIHObj.au3>
#include <WinAPIRes.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

Opt('TrayAutoPause', 0)

; Charge l'image
Global $g_hBitmap = _WinAPI_LoadImage(0, @ScriptDir & '\Extras\AutoIt.bmp', $IMAGE_BITMAP, 0, 0, $LR_LOADFROMFILE)
Local $tSIZE = _WinAPI_GetBitmapDimension($g_hBitmap)
Local $W = DllStructGetData($tSIZE, 'X')
Local $H = DllStructGetData($tSIZE, 'Y')

; Cr�e une GUI
Global $g_hForm = GUICreate('Test '& StringReplace(@ScriptName, '.au3', '()'), $W, $H + 26)
Global $g_idPic = GUICtrlCreatePic('', 0, 0, $W, $H)
GUICtrlCreateGraphic(0, $H, $W, 1)
GUICtrlSetBkColor(-1, 0xDFDFDF)
Global $g_idSlider = GUICtrlCreateSlider(0, $H + 1, $W, 25, BitOR($TBS_BOTH, $TBS_NOTICKS))
Global $g_hSlider = GUICtrlGetHandle(-1)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetData(-1, 255)

; D�finit bitmap � contr�ler avec alpha
_SetBitmapAlpha($g_idPic, $g_hBitmap, 255)

; Enregistre le message WM_HSCROLL pour un d�filement en direct et affiche la GUI
GUIRegisterMsg($WM_HSCROLL, 'WM_HSCROLL')
GUISetState(@SW_SHOW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _SetBitmapAlpha($hWnd, $hBitmap, $iAlpha)
    If Not IsHWnd($hWnd) Then
        $hWnd = GUICtrlGetHandle($hWnd)
        If Not $hWnd Then
            Return 0
        EndIf
    EndIf

    Local $aW[2], $aH[2]
    Local $tRECT = _WinAPI_GetClientRect($hWnd)
    $aW[0] = DllStructGetData($tRECT, 3) - DllStructGetData($tRECT, 1)
    $aH[0] = DllStructGetData($tRECT, 4) - DllStructGetData($tRECT, 2)
    Local $tSIZE = _WinAPI_GetBitmapDimension($hBitmap)
    $aW[1] = DllStructGetData($tSIZE, 1)
    $aH[1] = DllStructGetData($tSIZE, 2)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmapEx($hDC, $aW[0], $aH[0], 0xFFFFFF)
    Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBmp)
    Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBitmap)
    _WinAPI_AlphaBlend($hDestDC, 0, 0, $aW[0], $aH[0], $hSrcDC, 0, 0, $aW[1], $aH[1], $iAlpha, 0)
    _WinAPI_SelectObject($hDestDC, $hDestSv)
    _WinAPI_DeleteDC($hDestDC)
    _WinAPI_SelectObject($hSrcDC, $hSrcSv)
    _WinAPI_DeleteDC($hSrcDC)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Local $hObj = _SendMessage($hWnd, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hObj Then
        _WinAPI_DeleteObject($hObj)
    EndIf
    $hObj = _SendMessage($hWnd, $STM_GETIMAGE)
    If $hObj <> $hBmp Then
        _WinAPI_DeleteObject($hBmp)
    EndIf
    Return 1
EndFunc   ;==>_SetBitmapAlpha

Func WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg,$wParam

    If $hWnd = $g_hForm Then
        If $lParam = $g_hSlider Then
            _SetBitmapAlpha($g_idPic, $g_hBitmap, GUICtrlRead($g_idSlider))
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_HSCROLL