Render method
we have to add Directshow.net as a reference.
( download it from sourceforge.net)
Render Method Sample application in C# with directshow :
--------------------------------------------------------------------------------------
using System.Runtime.InteropServices;
using DirectShowLib;
namespace RenderMethod
{
class RenderMethod
{
private IGraphBuilder m_pGraphBuilder = null;
private IMediaControl m_pMediaControl = null;
private IMediaEventEx m_pMediaEventEx = null;
private IMediaSeeking m_pMediaSeeking = null;
private IBaseFilter m_pSourceFilter = null;
private IPin m_pOutputPin = null;
public RenderMethod()
{
m_pGraphBuilder = (IGraphBuilder)new FilterGraph();
}
~RenderMethod()
{
CloseInterfaces();
}
public int AddSourceFilter(string sourceFilename)
{
int hr = 0;
if (m_pGraphBuilder == null)
{
return DsResults.E_CannotRender;
}
hr = m_pGraphBuilder.AddSourceFilter(sourceFilename, sourceFilename, out m_pSourceFilter);
DsError.ThrowExceptionForHR(hr);
return hr;
}
public int Render()
{
int hr = 0;
m_pOutputPin = DsFindPin.ByDirection(m_pSourceFilter, PinDirection.Output, 0);
hr = m_pGraphBuilder.Render(m_pOutputPin);
DsError.ThrowExceptionForHR(hr);
m_pMediaControl = m_pGraphBuilder as IMediaControl;
m_pMediaEventEx = m_pGraphBuilder as IMediaEventEx;
m_pMediaSeeking = m_pGraphBuilder as IMediaSeeking;
hr = m_pMediaControl.Run();
DsError.ThrowExceptionForHR(hr);
return hr;
}
private void CloseInterfaces()
{
if (m_pGraphBuilder != null)
{
Marshal.ReleaseComObject(m_pGraphBuilder);
}
GC.Collect();
}
}
}
Client Usage of a class :
RenderMethod renderMethod = null;
renderMethod.AddSourceFilter("D:\\hands.avi");
renderMethod.Render();
( download it from sourceforge.net)
Render Method Sample application in C# with directshow :
--------------------------------------------------------------------------------------
using System.Runtime.InteropServices;
using DirectShowLib;
namespace RenderMethod
{
class RenderMethod
{
private IGraphBuilder m_pGraphBuilder = null;
private IMediaControl m_pMediaControl = null;
private IMediaEventEx m_pMediaEventEx = null;
private IMediaSeeking m_pMediaSeeking = null;
private IBaseFilter m_pSourceFilter = null;
private IPin m_pOutputPin = null;
public RenderMethod()
{
m_pGraphBuilder = (IGraphBuilder)new FilterGraph();
}
~RenderMethod()
{
CloseInterfaces();
}
public int AddSourceFilter(string sourceFilename)
{
int hr = 0;
if (m_pGraphBuilder == null)
{
return DsResults.E_CannotRender;
}
hr = m_pGraphBuilder.AddSourceFilter(sourceFilename, sourceFilename, out m_pSourceFilter);
DsError.ThrowExceptionForHR(hr);
return hr;
}
public int Render()
{
int hr = 0;
m_pOutputPin = DsFindPin.ByDirection(m_pSourceFilter, PinDirection.Output, 0);
hr = m_pGraphBuilder.Render(m_pOutputPin);
DsError.ThrowExceptionForHR(hr);
m_pMediaControl = m_pGraphBuilder as IMediaControl;
m_pMediaEventEx = m_pGraphBuilder as IMediaEventEx;
m_pMediaSeeking = m_pGraphBuilder as IMediaSeeking;
hr = m_pMediaControl.Run();
DsError.ThrowExceptionForHR(hr);
return hr;
}
private void CloseInterfaces()
{
if (m_pGraphBuilder != null)
{
Marshal.ReleaseComObject(m_pGraphBuilder);
}
GC.Collect();
}
}
}
Client Usage of a class :
RenderMethod renderMethod = null;
renderMethod.AddSourceFilter("D:\\hands.avi");
renderMethod.Render();
Labels: C# with Directshow
0 Comments:
Post a Comment
<< Home