DShow 中使用 IVMRMixerBitmap9::SetAlphaBitmap 返回为E_INVALIDARG,请帮忙!
对DShow不是很熟,目标是在视频上蒙一层自己绘制的线条
代码如下:
class myClass
{
....
}
HRESULT myClass::initVals(IGraphBuilder* pGraph, HWND parentHWND, CRect* pRect)
{// pRect 是当前的窗口对应的客户区的矩形
CStringA strMsg;
// create the VMR9 filter
CoCreateInstance(CLSID_VideoMixingRenderer9, NULL, CLSCTX_INPROC,
IID_IBaseFilter, (void**)&pVmr);
// add the VMR9 filter to the Graph Manager
HRESULT rt = pGraph->AddFilter(pVmr, L"Video_");
//strMsg.Format("\n retV:%d, p:%d",rt, (int)pVmr);
//OutputDebugStringA(strMsg);
if(rt != S_OK)
{
return rt;
}
// get a pointer to the IVMRFilterConfig9 interface
rt = pVmr->QueryInterface(IID_IVMRFilterConfig9, (void**)&pConfig);
//strMsg.Format("\n retV:%d, p:%d",rt, (int)pConfig);
//OutputDebugStringA(strMsg);
if(rt != S_OK)
{
return rt;
}
// make sure VMR9 is in windowless mode
//rt = pConfig->SetNumberOfStreams(4);
//strMsg.Format("\n retV:%d",rt);
//OutputDebugStringA(strMsg);
rt = pConfig->SetRenderingMode(VMR9Mode_Windowless);
strMsg.Format("\n retV:%d",rt);
OutputDebugStringA(strMsg);
//rt = pConfig->SetRenderingPrefs(RenderPrefs_AllowOverlays);
//strMsg.Format("\n retV:%d",rt);
//OutputDebugStringA(strMsg);
if(rt != S_OK)
{
return rt;
}
rt = pConfig->Release();
pConfig = NULL;
// get a pointer to the IVMRWindowlessControl9 interface
rt = pVmr->QueryInterface(IID_IVMRWindowlessControl9, (void**)&pWC);
//strMsg.Format("\n retV:%d, p:%d",rt, (int)pWC);
//OutputDebugStringA(strMsg);
if(rt != S_OK)
{
return rt;
}
// set destination rectangle for the video
//pRect->left -= 20;
//pRect->top -= 20;
//pRect->right -= 20;
//pRect->bottom -= 20;
rt = pWC->SetVideoPosition(NULL, pRect);
//strMsg.Format("\n retV:%d",rt);
//OutputDebugStringA(strMsg);
if(rt != S_OK)
{
return rt;
}
// specify the container window that the video should be clipped to
rt = pWC->SetVideoClippingWindow(parentHWND);
//strMsg.Format("\n retV:%d",rt);
//OutputDebugStringA(strMsg);
if(rt != S_OK)
{
return rt;
}
// used for display of bmp on video
rt = pWC->QueryInterface(IID_IVMRMixerBitmap9, (LPVOID *)&pBmp);
//strMsg.Format("\n retV:%d, p:%d",rt, (int)pBmp);
//OutputDebugStringA(strMsg);
if(rt != S_OK)
{
return rt;
}
ZeroMemory(&bmpInfo, sizeof(bmpInfo) );
// bmpInfo.dwFlags |= VMRBITMAP_HDC;
// Set the transparency value (1.0 is opaque, 0.0 is transparent).
return S_OK;
}
//上面这个函数,都没有错误出现
//问题出在下面这个函数
HRESULT myClass::createCompDC_BMP(CDC* pdc, CRect ctrlRect)
{//此处CtrlRect可能会变化
if(fBmpCompWidth != 0)
{
DeleteObject(m_hBitmap);
}
CStringA strMsg;
HRESULT rt = pWC->SetVideoPosition(NULL, &ctrlRect);
strMsg.Format("\n ret for set:0X%x \n",rt);
OutputDebugStringA(strMsg);
//CSize sz = pdc->GetWindowExt();
fBmpCompWidth = ctrlRect.Width();//sz.cx;
fBmpCompHeight = ctrlRect.Height();//sz.cy;
strMsg.Format("\n size sz: cx:%d; cy:%d \n",fBmpCompWidth, fBmpCompHeight);
OutputDebugStringA(strMsg);
//创建兼容DC
CDC mCompatibleDC;
if(!mCompatibleDC.CreateCompatibleDC(pdc))
{
return S_FALSE;
}
//创建位图
if(!m_myBitmap.CreateCompatibleBitmap(pdc, fBmpCompWidth, fBmpCompHeight))
{
return S_FALSE;
}//rect.Width(), rect.Height());
m_hBitmap = (HBITMAP)m_myBitmap;
pdc->DeleteDC();
mCompatibleDC.SelectObject(&m_myBitmap);
CPen pen(PS_SOLID, 3, RGB(250, 0, 0));
CPen *curPen = mCompatibleDC.SelectObject(&pen);
mCompatibleDC.FillSolidRect(0, 0, fBmpCompWidth, fBmpCompHeight, m_polygonBGClr);
mCompatibleDC.MoveTo(0, 20);
mCompatibleDC.LineTo(fBmpCompWidth - 1, 20);
mCompatibleDC.SelectObject(curPen);
///////////////set bmpInfo
bmpInfo.dwFlags |= VMRBITMAP_HDC;
bmpInfo.fAlpha = 0.9f;
//
bmpInfo.hdc = mCompatibleDC.m_hDC;
CRect myRect;
myRect.SetRect(0, 0, fBmpCompWidth, fBmpCompHeight);
strMsg.Format("\n myRect: left:%d; right:%d; top:%d; bottom:%d \n",myRect.left, myRect.right, myRect.top, myRect.bottom);
OutputDebugStringA(strMsg);
bmpInfo.rSrc = myRect;
bmpInfo.rDest.right = 1.0f;
bmpInfo.rDest.left = 0.0f;
bmpInfo.rDest.top = 0.0f;
bmpInfo.rDest.bottom = 1.0f;
bmpInfo.clrSrcKey = m_polygonBGClr;
bmpInfo.dwFlags |= VMRBITMAP_SRCCOLORKEY;
strMsg.Format("\n dwFlag: 0X%x \n",bmpInfo.dwFlags);
OutputDebugStringA(strMsg);
//VMRALPHABITMAP oldBmp;
//pBmp->GetAlphaBitmapParameters(&oldBmp);
rt = pBmp->SetAlphaBitmap(&bmpInfo);
strMsg.Format("\n ret for set:0X%x \n",rt);
OutputDebugStringA(strMsg);//此处输出: ret for set:0X80070057
return S_OK;
}