Silverlight 4 introduces WebCam support which is probably the highlight of the Silverlight 4 release. The WebCam API is relatively simple to use, a webcam can be added, video captured and placed on the screen using the following procedure:
WebCam Video Capture Procedure
- Add a rectangle plus a button.
- Get a handle on the video capture device using CaptureDeviceConfiguration.
- Request access to the WebCam using CaptureDeviceConfiguration.RequestDeviceAccess().
- After the user clicks Yes at the prompt , create a CaptureSource object and set the VideoCaptureDevice to the selected webcam.
- Create a VideoBrush and set its source.
- Start the WebCam.
- Fill the Rectangle.
Code for WebCam Video Capture
//access the WebCam
VideoCaptureDevice webcamObj = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
//user confirmation clips
if (CaptureDeviceConfiguration.RequestDeviceAccess())
CaptureSource captureSourceObj = new CaptureSource();
captureSourceObj.VideoCaptureDevice = webcamObj;
VideoBrush videoBrushObj = new VideoBrush();
videoBrushObj.SetSource(captureSourceObj);
videoBrushObj.Stretch = Stretch.UniformToFill;
//start WebCam
videoBrushObj.Start();
//fill the rectangle with the video
this.MyVideo.Fill = videoBrushObj;
This code only works for a single WebCam but CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices will return a list of all available webcams.