3

I am a beginner directshow programmer I am trying to make WPF App that contain (live feed) from certain web camera

and then I can snap a picture from this "live feed"

I defined a GraphBuilder and I did as following :

static void BuildGraph(IGraphBuilder pGraph)
{
    //graph builder
    int hr = 0;
    ICaptureGraphBuilder2 pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
    hr = pBuilder.SetFiltergraph(pGraph);

    Guid clsid_VidCapSource = new Guid("{860BB310-5D01-11D0-BD3B-00A0C911CE86}");

    //add myCam
    IBaseFilter mycam = CreateFillterByName("QuickCam Communicate Deluxe", clsid_VidCapSource);
    hr = pGraph.AddFilter(mycam, "QuickCam Communicate Deluxe");


    //add color space converter
    IBaseFilter pColorSpaceConverter3 = (IBaseFilter)new Colour();
    hr = pGraph.AddFilter(pColorSpaceConverter3, "Color Space Converter");


    //connect myCam, pColorSpaceConverter
    hr = pGraph.ConnectDirect(GetPin(mycam, "Capture"), GetPin(pColorSpaceConverter3, "Input"), null);

}

after that I build a graph :

private void Button_Click(object sender, RoutedEventArgs e)
{
    IGraphBuilder graph = (IGraphBuilder)new FilterGraph();
    BuildGraph(graph);
    IMediaControl mediaControl = (IMediaControl)graph;
    mediaControl.Run();
}

How can I render the output of this graph onto my WPF window

note: after build the graph the camera led indicate that the camera is capturing.

thanks in advance

Amer Sawan
  • 2,126
  • 1
  • 22
  • 40

2 Answers2

4

Basically, you need to add a SampleGrabber filter just after your video device filter to get video frames and "render" the video to a null renderer filter.

The SampleGrabber will update a buffer containing the current frame. This buffer is used to create an InteropBitmap and to bring the image into the WPF world. Then you can create an ImageBrush from the InteropBitmap, and use it as a Background for any UIElement.

See the following project: http://wpfcap.codeplex.com/ which do exactly what I've briefly described.

Jerome Thievent
  • 295
  • 2
  • 8