Getting Started

This tutorial will walk you through the creation of a sample application that contains RadWebCam.

Assembly References

In order to use RadWebCam, you will need to add references to the following assemblies:

  • Telerik.Windows.Controls
  • Telerik.Windows.Controls.Media
  • Telerik.Windows.MediaFoundation
  • MediaFoundation: This dll is located in the UI for WPF installation folder/Binaries/WPF40/MediaFoundation folder.
  • SharpDX: This dll is located in the UI for WPF installation folder/Binaries/WPF40/SharpDX folder.
  • SharpDX.Direct3D9: This dll is located in the UI for WPF installation folder/Binaries/WPF40/SharpDX folder.

You can find the required assemblies for each control from the suite in the Controls Dependencies help article.

Setting up the Control

To start using the control you only need to add it in the visual tree through XAML or code-behind. This will automatically detect a web camera if one is connected to the device and start reciving the media stream, thus showing the camera input.

Example 1: Defining RadWebCam in XAML

<telerik:RadWebCam /> 

Example 2: Defining RadWebCam in code

RadWebCam radWebCam = new RadWebCam();   
From this point on, you can start using the control without any additional set up.

Figure 1: RadWebCam

Auto Start

By default the camera control will start automatically if a camera device is connected. You can change this by setting the AutoStart property of RadWebCam to False.

Example 3: Setting AutoStart in XAML

 <telerik:RadWebCam AutoStart="False"/> 

Example 4: Setting AutoStart in code

this.radWebCam.AutoStart = false; 

Connect to the Webcam Manually

To connect to the webcam manually you can call the Start method of the control.

Example 5: Starting the camera

this.radWebCam.Start(); 
To connect to a webcam manually, execute the following steps.
  1. Get the camera device. To do this, use the RadWebCam GetVideoCaptureDevices static method.
  2. Get a video format from the camera. To do this, use the RadWebCam GetVideoFormats static methods.
  3. Initialize the camera device in the control. To do this, use the Initialize method of the RadWebCam control.
  4. Start the webcam control. To do this, use the Start method of the control.

Example 6: Starting the camera with manually set device and video format

ReadOnlyCollection<MediaFoundationDeviceInfo> videoDevices = RadWebCam.GetVideoCaptureDevices();             
ReadOnlyCollection<MediaFoundationVideoFormatInfo> videoFormats = RadWebCam.GetVideoFormats(videoDevices[0]); 
this.radWebCam.Initialize(videoDevices[0], videoFormats[0]); 
this.radWebCam.Start(); 

Read more about the capture devices in the Media Information article.

Stop the Camera Control

To stop the stream between the camera device and the RadWebCam control, call the Stop method.

Example 7: Stopping the camera

this.radWebCam.Stop(); 

Recording Video

To record a video you need to set RecordingFilePath before start the recording. This is requried in order to specify where the recording will be stored on the file system.

To start recording, press the "Start recording" button or call the StartRecording method of RadWebCam. This will start writing the media stream to the corresponding file.

Example 8: Set the recording file path in XAML

<telerik:RadWebCam RecordingFilePath="C:\temp\video.mp4"/> 

Read more about this in the Recording Video article.

Taking Snapshot

A snapshot of the currently displayed video feed can be taken using the TakeSnapshot method of the control, or by pressing the "Take snapshot button". This will fire the SnapshotTaken event where you get access the current snapshot as a BitmapSource object.

Example 9: Subscribing to the SnapshotTaken event

public MainWindow() 
{ 
    InitializeComponent(); 
 
    this.radWebCam.SnapshotTaken += RadWebCam_SnapshotTaken; 
} 
 
private void RadWebCam_SnapshotTaken(object sender, SnapshotTakenEventArgs e) 
{ 
    BitmapSource snapshot = e.Snapshot; 
    // here you save the source to a file, in memory, or to show it in the UI 
} 

See Also

In this article
Not finding the help you need? Improve this article