尝试制作 VMR-9 MixerBitmap & GDI工作
我正在尝试在某些视频上叠加位图。我在内存中创建一个位图,然后调用 SelectObject 将其选择到内存 DC 中,这样我就可以对其执行 DrawText 操作。
我在屏幕上根本没有得到任何结果 - 谁能告诉我为什么?
谢谢
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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了这个问题,所以如果其他人需要知道它是如何完成的......
I got this one solved, so if anyone else needs to know how it's done...