Share via


IMFVideoMixerBitmap::SetAlphaBitmap 方法 (evr9.h)

將增強式視訊轉譯器 (EVR) 的點陣圖影像設定為與視訊的 Alpha 混合。

語法

HRESULT SetAlphaBitmap(
  [in] const MFVideoAlphaBitmap *pBmpParms
);

參數

[in] pBmpParms

MFVideoAlphaBitmap結構的指標,其中包含點陣圖、來源和目的地矩形、色彩索引鍵和其他資訊的相關資訊。

傳回值

方法會傳回 HRESULT。 可能的值包括 (但不限於) 下表中的這些值。

傳回碼 描述
S_OK
此方法已成功。
E_INVALIDARG
pBmpParms結構中定義的混合參數無效。

備註

應用程式可以將影像提供為 GDI 點陣圖或 Direct3D 表面。 EVR 混音器會將影像與下一個視訊框架和所有後續畫面混合,直到影像變更或移除為止。 影像可以包含內嵌的個別圖元 Alpha 資訊,以便定義透明區域。 透明區域也可以使用色彩索引鍵值來識別。

如果您使用 Direct3D 表面,則介面格式必須是 32 位 RGB,D3DFMT_X8R8G8B8或D3DFMT_A8R8G8B8,而且介面必須從D3DPOOL_SYSTEMMEM記憶體集區配置。

您可以將影像傳遞至視訊轉譯器的頻率沒有定義的限制。 不過,每秒變更影像數次可能會影響視訊的效能和平滑度。

範例

下列範例會設定 Alpha 混合的 GDI 點陣圖。 針對範例的目的,它會使用目的地矩形和 Alpha 值的預先定義設定。

HRESULT EVRPlayer::SetBitmapImage(BOOL bEnable, HBITMAP hBitmap)
{
    const float fBitmapAlpha = 0.5f; 

    HRESULT hr = S_OK;

    // To enable the bitmap, you must supply a valid bitmap handle.
    if (bEnable && (hBitmap == NULL))
    {
        return E_INVALIDARG;
    }
    
    // Make sure we have an IMFVideoMixerBitmap pointer.
    if (m_pMixerBitmap == NULL)
    {
        return E_FAIL;
    }

    if (bEnable)
    {
        // Place the bitmap in the lower-right quadrant of the video.
        MFVideoNormalizedRect nrcDest = { 0.5f, 0.5f, 1.0f, 1.0f };

        // Get the device context for the video window.
        HDC hdc = GetDC(m_hwndVideo);

        // Create a compatible DC and select the bitmap into the DC>
        HDC hdcBmp = CreateCompatibleDC(hdc);
        HBITMAP hOld = (HBITMAP)SelectObject(hdcBmp, hBitmap);

        // Fill in the blending parameters.
        MFVideoAlphaBitmap bmpInfo;
        ZeroMemory(&bmpInfo, sizeof(bmpInfo));
        bmpInfo.GetBitmapFromDC = TRUE; // Use a bitmap DC (not a Direct3D surface).
        bmpInfo.bitmap.hdc = hdcBmp;
        bmpInfo.params.dwFlags = 
            MFVideoAlphaBitmap_Alpha | MFVideoAlphaBitmap_DestRect;
        bmpInfo.params.fAlpha = fBitmapAlpha;
        bmpInfo.params.nrcDest = nrcDest;

        // Get the bitmap dimensions.
        BITMAP bm;
        GetObject(hBitmap, sizeof(BITMAP), &bm);

        // Set the source rectangle equal to the entire bitmap.
        SetRect(&bmpInfo.params.rcSrc, 0, 0, bm.bmWidth, bm.bmHeight);

        // Set the bitmap.
        hr = m_pMixerBitmap->SetAlphaBitmap(&bmpInfo);

        SelectObject(hdcBmp, hOld);
        DeleteDC(hdcBmp);
        ReleaseDC(m_hwndVideo, hdc);
    }
    else
    {
        hr = m_pMixerBitmap->ClearAlphaBitmap();
    }
    return hr;
}

需求

   
最低支援的用戶端 Windows Vista [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 [僅限傳統型應用程式]
目標平台 Windows
標頭 evr9.h
程式庫 Strmiids.lib

另請參閱

增強的視訊轉譯器

IMFVideoMixerBitmap