|
|
主要是要实现让某种颜色变的透明。
我的视频播放的方法是使用DX9SDK中的Texture3D例子
HRESULT InitDShowTextureRenderer()
{
HRESULT hr = S_OK;
CComPtr<IBaseFilter> pFSrc; // Source Filter
CComPtr<IPin> pFSrcPinOut; // Source Filter Output Pin
CTextureRenderer *pCTR=0; // DirectShow Texture renderer
// Create the filter graph
if (FAILED(g_pGB.CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC)))
return E_FAIL;
#ifdef REGISTER_FILTERGRAPH
// Register the graph in the Running Object Table (for debug purposes)
AddToROT(g_pGB);
#endif
// Create the Texture Renderer object
pCTR = new CTextureRenderer(NULL, &hr);
if (FAILED(hr) || !pCTR)
{
Msg(TEXT("Could not create texture renderer object! hr=0x%x"), hr);
return E_FAIL;
}
// Get a pointer to the IBaseFilter on the TextureRenderer, add it to graph
g_pRenderer = pCTR;
if (FAILED(hr = g_pGB->AddFilter(g_pRenderer, L"TEXTURERENDERER")))
{
Msg(TEXT("Could not add renderer filter to graph! hr=0x%x"), hr);
return hr;
}
// Determine the file to load based on DirectX Media path (from SDK)
// Use a helper function included in DXUtils.cpp
TCHAR strFileName[MAX_PATH];
WCHAR wFileName[MAX_PATH];
lstrcpyn( strFileName, DXUtil_GetDXSDKMediaPath(), MAX_PATH-1 );
lstrcat( strFileName, SOURCE_FILE );
strFileName[MAX_PATH-1] = 0; // NULL-terminate
wFileName[MAX_PATH-1] = 0; // NULL-terminate
USES_CONVERSION;
wcsncpy(wFileName, T2W(strFileName), NUMELMS(wFileName));
// Add the source filter to the graph.
hr = g_pGB->AddSourceFilter (wFileName, L"SOURCE", &pFSrc);
// If the media file was not found, inform the user.
if (hr == VFW_E_NOT_FOUND)
{
Msg(TEXT("Could not add source filter to graph! (hr==VFW_E_NOT_FOUND)\r\n\r\n")
TEXT("This sample reads a media file from the DirectX SDK's media path.\r\n")
TEXT(" lease install the DirectX 9 SDK on this machine."));
return hr;
}
else if(FAILED(hr))
{
Msg(TEXT("Could not add source filter to graph! hr=0x%x"), hr);
return hr;
}
if (FAILED(hr = pFSrc->FindPin(L"Output", &pFSrcPinOut)))
{
Msg(TEXT("Could not find output pin! hr=0x%x"), hr);
return hr;
}
#ifdef NO_AUDIO_RENDERER
// If no audio component is desired, directly connect the two video pins
// instead of allowing the Filter Graph Manager to render all pins.
CComPtr<IPin> pFTRPinIn; // Texture Renderer Input Pin
// Find the source's output pin and the renderer's input pin
if (FAILED(hr = pFTR->FindPin(L"In", &pFTRPinIn)))
{
Msg(TEXT("Could not find input pin! hr=0x%x"), hr);
return hr;
}
// Connect these two filters
if (FAILED(hr = g_pGB->Connect(pFSrcPinOut, pFTRPinIn)))
{
Msg(TEXT("Could not connect pins! hr=0x%x"), hr);
return hr;
}
#else
// Render the source filter's output pin. The Filter Graph Manager
// will connect the video stream to the loaded CTextureRenderer
// and will load and connect an audio renderer (if needed).
if (FAILED(hr = g_pGB->Render(pFSrcPinOut)))
{
Msg(TEXT("Could not render source output pin! hr=0x%x"), hr);
return hr;
}
#endif
// Get the graph's media control, event & position interfaces
g_pGB.QueryInterface(&g_pMC);
g_pGB.QueryInterface(&g_pMP);
g_pGB.QueryInterface(&g_pME);
// Start the graph running;
if (FAILED(hr = g_pMC->Run()))
{
Msg(TEXT("Could not run the DirectShow graph! hr=0x%x"), hr);
return hr;
}
return S_OK;
}
在对bmp平面图的处理中可以用颜色键屏蔽掉某种颜色
D3DXCreateTextureFromFileEx(pd3dDevice, "*.bmp", 0, 0, 0, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(0, 0, 0), NULL, NULL, &m_pTexture);
但是在播放视频时好像不行?
请大家帮帮我,多谢! |
|