DShow采集如何与VMR-9预览结合起来参考上一篇文章。要在VMR-9预览上叠加GDI的绘图,需要自己创建一个BITMAP,把东西在BITMAP上都画好了,再使用IVMRMixerBitmap9::SetAlphaBitmap叠加上去
hr = m_pVmrWc->QueryInterface(IID_IVMRMixerBitmap9, (LPVOID *)&m_pBmp);
......
HRESULT CDShowDevStream::DrawLine()
{
HWND hwnd;
HDC dc, dcMem;
RECT rc;
HBITMAP bmpMem;
HGDIOBJ bmpOld;
hwnd = (HWND)param_.window.info.win.hwnd;
dc = ::GetDC(hwnd);
dcMem = ::CreateCompatibleDC(dc);
::GetClientRect(hwnd, &rc);
bmpMem = ::CreateCompatibleBitmap(dc, rc.right, rc.bottom);
bmpOld = ::SelectObject(dcMem, bmpMem);
// Draw a line on bitmap
HPEN pen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
HPEN oldPen = (HPEN)SelectObject(dcMem, pen);
MoveToEx(dcMem, 0, 0, NULL);
LineTo(dcMem, 100, 150);
SelectObject(dcMem, oldPen);
DeleteObject(pen);
VMR9AlphaBitmap bmpInfo;
ZeroMemory(&bmpInfo, sizeof(bmpInfo));
bmpInfo.dwFlags = VMRBITMAP_HDC;
bmpInfo.hdc = dcMem;
// Show the entire bitmap in the video image.
SetRect(&bmpInfo.rSrc, 0, 0, rc.right, rc.bottom);
// rDest specifies the destination rectangle in composition space (0.0f to 1.0f)
bmpInfo.rDest.left = 0.f;
bmpInfo.rDest.top = 0.f;
bmpInfo.rDest.right = 1.0f;
bmpInfo.rDest.bottom = 1.0f;
// Set the COLORREF so that the bitmap outline will be transparent
bmpInfo.dwFlags |= VMRBITMAP_SRCCOLORKEY;
bmpInfo.clrSrcKey = RGB(0, 0, 0);
// Set the transparency value (1.0 is opaque, 0.0 is transparent).
bmpInfo.fAlpha = 1.0f;
HRESULT hr = m_pBmp->SetAlphaBitmap(&bmpInfo);
// Cleanup.
::SelectObject(dcMem, bmpOld);
::DeleteObject(bmpMem);
::DeleteDC(dcMem);
ReleaseDC(hwnd, dc);
return hr;
}
参考
https://msdn.microsoft.com/en-us/library/windows/desktop/dd375479(v=vs.85).aspx
https://stackoverflow.com/questions/3015307/trying-to-make-vmr-9-mixerbitmap-gdi-work
https://www.codeproject.com/Articles/15531/Showing-an-animated-image-over-running-video
网友评论