Author : Aamir Hasan
This is my first tutorial on silverlight.In this article i am going tell you how to utilize a user's web camera and microphone attached to their computer via the browser, to capturing audio and video.
First you have to add namespace in your cs file as given below
using System.Windows.Media;
using System.Windows.Media.Imaging;
ObservableCollection images adding images to it:
CaptureSource _captureSource;
ObservableCollection<WriteableBitmap> _images = new ObservableCollection<WriteableBitmap>();
Caturing the video
if (_captureSource != null)
{
_captureSource.Stop(); // stop whatever device may be capturing
// set the devices for the capture source
_captureSource.VideoCaptureDevice = (VideoCaptureDevice)VideoSources.SelectedItem;
_captureSource.AudioCaptureDevice = (AudioCaptureDevice)AudioSources.SelectedItem;
// create the brush
VideoBrush vidBrush = new VideoBrush();
vidBrush.SetSource(_captureSource);
WebcamCapture.Fill = vidBrush; // paint the brush on the rectangle
// request user permission and display the capture
if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
{
_captureSource.Start();
}
}
Create a Snapshot from the Video
When the capture process has started and a user clicks the Take Snapshot button, the appropriate command is invoked in the VM and the capture source’s AsyncCaptureImage method is invoked. I used the Dispatcher to make sure I operated on the UI thread because I wanted to not only grab the bitmap.
private void StopCapture_Click(object sender, RoutedEventArgs e)
{
if (_captureSource != null)
{
_captureSource.Stop();
}
}
private void TakeSnapshot_Click(object sender, RoutedEventArgs e)
{
if (_captureSource != null)
{
// capture the current frame and add it to our observable collection
_captureSource.AsyncCaptureImage((snapImage) =>
{
_images.Add(snapImage);
});
}
}
Author:
Aamir Hasan औथोर:
आमिर हसन أثر
أمير حسن .
77553f53-176b-45ba-bf11-ad82bf09d0ad|0|.0
ALL, CSharp
asp.net, silverlight