I'm attempting to overlay a bitmap on some video. I create a bitmap in memory, then I call SelectObject to select it into a memoryDC, so I can perform a DrawText operation on it.
I'm not getting any results on screen at all - can anyone suggest why?
thanks
HRESULT MyGraph::MixTextOverVMR9(LPCTSTR szText)
{
// create a bitmap object using GDI, render the text to it accordingly
// then Sets the bitmap as an alpha bitmap to the VMR9, so that it can be overlayed.
HRESULT hr = S_OK;
CBitmap bmpMem;
CFont font;
LOGFONT logicfont;
CRect rcText;
CRect rcVideo;
VMR9AlphaBitmap alphaBmp;
HWND hWnd = this->GetFirstRendererWindow();
COLORREF clrText = RGB(255, 255, 0);
COLORREF clrBlack = RGB(0,0,0);
HDC hdcHwnd = NULL;
CDC dcMem;
LONG lWidth;
LONG lHeight;
if( ! m_spVideoRenderer.p )
return E_NOINTERFACE;
if( !m_spWindowlessCtrl.p )
return E_NOINTERFACE;
if( ! m_spIMixerBmp9.p )
{
m_spIMixerBmp9 = m_spVideoRenderer;
if( ! m_spIMixerBmp9.p )
return E_NOINTERFACE;
}
// create the font..
LPCTSTR sFont = _T("Times New Roman");
memset(&logicfont, 0, sizeof(LOGFONT));
logicfont.lfHeight = 42;
logicfont.lfWidth = 20;
logicfont.lfStrikeOut = 0;
logicfont.lfUnderline = 0;
logicfont.lfItalic = FALSE;
logicfont.lfWeight = FW_NORMAL;
logicfont.lfEscapement = 0;
logicfont.lfCharSet = ANSI_CHARSET;
logicfont.lfQuality = ANTIALIASED_QUALITY;
logicfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
wcscpy_s( &logicfont.lfFaceName[0], wcslen(sFont)*2, sFont );
font.CreateFontIndirectW(&logicfont);
// create a compatible memDC from the video window's HDC
if( hWnd == NULL )
return E_FAIL;
hdcHwnd = GetDC(hWnd);
dcMem = CreateCompatibleDC(hdcHwnd);
// get the required bitmap metrics from the MediaBuffer
if( ! SUCCEEDED(m_spWindowlessCtrl->GetNativeVideoSize(&lWidth, &lHeight, NULL, NULL)) )
return E_FAIL;
// create a bitmap for the text
bmpMem.CreateCompatibleBitmap(dcMem.m_hDC, lWidth, lHeight);
SelectBitmap (dcMem.m_hDC, bmpMem);
SetBkMode (dcMem.m_hDC, TRANSPARENT);
SetTextColor (dcMem.m_hDC, clrText);
SelectFont (dcMem.m_hDC, font.m_hFont);
// draw the text
DrawTextW(dcMem.m_hDC, szText, wcslen(szText), rcText, DT_CALCRECT | DT_NOPREFIX );
DrawTextW(dcMem.m_hDC, szText, wcslen(szText), rcText, DT_NOPREFIX );
// Set the alpha bitmap on the VMR9 renderer
memset(&alphaBmp, 0, sizeof(VMR9AlphaBitmap));
alphaBmp.rDest.left = 0;
alphaBmp.rDest.top = 0.5;
alphaBmp.rDest.right = 0.5;
alphaBmp.rDest.bottom = 1;
alphaBmp.dwFlags = VMR9AlphaBitmap_hDC;
alphaBmp.hdc = dcMem.m_hDC;
alphaBmp.pDDS = NULL;
alphaBmp.rSrc = rcText; // rect to copy from the source image
alphaBmp.fAlpha = 0.5f; // transparency value (1.0 is opaque, 0.0 is transparent)
alphaBmp.clrSrcKey = clrText;
// alphaBmp.dwFilterMode = MixerPref9_AnisotropicFiltering;
hr = m_spIMixerBmp9->SetAlphaBitmap(&alphaBmp);
DeleteDC(hdcHwnd);
dcMem.DeleteDC();
bmpMem.DeleteObject();
font.DeleteObject();
return hr;
}