Click here to Skip to main content
Click here to Skip to main content

WPF: Webcam Control

By , 11 Feb 2013
 
Prize winner in Competition "Best VB.NET article of November 2011"

WPF_WebcamControl/Screenshot_1.png

Introduction

I have on several occasions scoured the net for a simple to use WPF webcam control and either my search queries were awful or I just wasn't comfortable with whatever I found. This webcam interest was recently increased when I read an article, here on CodeProject, that referred to an application that made use of a webcam. It was a Silverlight article and the ease with which one could utilize a webcam in Silverlight made me envious of WPF's little brother (or is it sister?). The VideoBrush in Silverlight is especially a nice touch.

It is with this pain and envy in mind that I decided to try my hand at creating a WPF control that could;

  1. Display webcam video with little coding effort,
  2. Allow saving of webcam video to harddisk, with little coding effort,
  3. Save the webcam video in a variety of video formats

Background

With the previously mentioned goals in mind, I created a WPF UserControl that has the following features,

  • Displays webcam video,
  • Enables saving of webcam videos to harddisk,
  • Enables saving of webcam videos in either .wmv, .mp4, or .flv format

The UserControl also enables you to take a snapshot of the live webcam video, and save it as a Jpeg, Png, Gif, or any other of the ImageFormat properties.

The Webcam control makes heavy use of the Expression Encoder 4 SDK. You therefore need to have the SDK installed on your machine to make use of the UserControl. You can download the SDK from here.

Requirements

To make use of the Webcam control, you require;

  • .NET Framework 4.0
  • Expression Encoder SDK

Using the Webcam Control

To use the Webcam control in your WPF application add a reference to WebcamControl.dll and a using/Imports statement for WebcamControl at the top of your class.

Add a reference to Microsoft.Expression.Encoder.dll . Do this by using the Add Reference dialog box, selecting the .NET tab, and selecting Microsoft.Expression.Encoder from the listbox. The Expression Encoder assemblies should be available if you have installed Expression Encoder 4.

The following example, which is the downloadable sample application, shows the use of the Webcam control. The Webcam control is defined in the Window's XAML markup.

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cam="clr-namespace:WebcamControl;assembly=WebcamControl"    
    ...
    >
    <Grid>
        <cam:Webcam Name="WebCamCtrl" Margin="12,12,12,204"></cam:Webcam>        
        ...
    </Grid>
</Window>

VB.NET

Imports Microsoft.Expression.Encoder.Devices
Imports WebcamControl
Imports System.IO
Imports Microsoft.Expression.Encoder.Live
Imports Microsoft.Expression.Encoder
Imports System.Drawing
Imports System.Drawing.Imaging

Class MainWindow

    ' Bind Webcam dependency properties to ComboBox property.   
    Private Sub MainWindow_Initialized(ByVal sender As Object, _
                                       ByVal e As System.EventArgs) Handles Me.Initialized
        Dim bndg_1 As New Binding("SelectedValue")
        bndg_1.Source = VidDvcsComboBox
        WebCamCtrl.SetBinding(Webcam.VideoDeviceProperty, bndg_1)

        Dim bndg_2 As New Binding("SelectedValue")
        bndg_2.Source = AudDvcsComboBox
        WebCamCtrl.SetBinding(Webcam.AudioDeviceProperty, bndg_2)
    End Sub

    Private Sub MainWindow_Loaded(ByVal sender As Object, _
                                  ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        FindDevices()

        Dim vidPath As String = "C:\VideoClips"
        Dim imgPath As String = "C:\WebcamSnapshots"

        If Directory.Exists(vidPath) = False Then
            Directory.CreateDirectory(vidPath)
        End If

        If Directory.Exists(imgPath) = False Then
            Directory.CreateDirectory(imgPath)
        End If

        ' Set some properties of the Webcam control.
        WebCamCtrl.VideoDirectory = vidPath
        WebCamCtrl.VidFormat = VideoFormat.mp4

        WebCamCtrl.ImageDirectory = imgPath
        WebCamCtrl.PictureFormat = ImageFormat.Jpeg
        
        WebCamCtrl.FrameRate = 30
        WebCamCtrl.FrameSize = New Size(320, 240)

        VidDvcsComboBox.SelectedIndex = 0
        AudDvcsComboBox.SelectedIndex = 0
    End Sub

    ' Find available a/v devices.
    Private Sub FindDevices()
        Dim vidDevices = EncoderDevices.FindDevices(EncoderDeviceType.Video)
        Dim audDevices = EncoderDevices.FindDevices(EncoderDeviceType.Audio)

        For Each dvc In vidDevices
            VidDvcsComboBox.Items.Add(dvc.Name)
        Next

        For Each dvc In audDevices
            AudDvcsComboBox.Items.Add(dvc.Name)
        Next
    End Sub

    Private Sub StartButton_Click(ByVal sender As System.Object, _
                                  ByVal e As System.Windows.RoutedEventArgs) _
                              Handles StartButton.Click
        ' Display webcam images on control.
        Try
            WebCamCtrl.StartCapture()
        Catch ex As Microsoft.Expression.Encoder.SystemErrorException
            MessageBox.Show("Device is in use by another application")
        End Try
    End Sub

    Private Sub EndButton_Click(ByVal sender As Object, _
                                ByVal e As System.Windows.RoutedEventArgs) _
                            Handles EndButton.Click
        ' Stop the display of webcam video.
        WebCamCtrl.StopCapture()
    End Sub

    Private Sub RecordButton_Click(ByVal sender As System.Object, _
                                   ByVal e As System.Windows.RoutedEventArgs) _
                               Handles RecordButton.Click
        ' Start recording of webcam video to harddisk.
        WebCamCtrl.StartRecording()
    End Sub

    Private Sub StopRecordButton_Click(ByVal sender As Object, _
                                       ByVal e As System.Windows.RoutedEventArgs) _
                                   Handles StopRecordButton.Click
        ' Stop recording of webcam video to harddisk.
        WebCamCtrl.StopRecording()
    End Sub

    Private Sub SnapshotButton_Click(ByVal sender As System.Object, _
                                     ByVal e As System.Windows.RoutedEventArgs) _
                                 Handles SnapshotButton.Click
        WebCamCtrl.TakeSnapshot()
    End Sub
End Class

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Expression.Encoder.Devices;
using WebcamControl;
using System.IO;
using System.Drawing.Imaging;

namespace WPF_Webcam
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        
        public MainWindow()
        {
            InitializeComponent();                    

            // Bind the Video and Audio device properties of the
            // Webcam control to the SelectedValue property of 
            // the necessary ComboBox.
            Binding bndg_1 = new Binding("SelectedValue");
            bndg_1.Source = VidDvcsComboBox;
            WebCamCtrl.SetBinding(Webcam.VideoDeviceProperty, bndg_1);

            Binding bndg_2 = new Binding("SelectedValue");
            bndg_2.Source = AudDvcsComboBox;
            WebCamCtrl.SetBinding(Webcam.AudioDeviceProperty, bndg_2);

            // Create directory for saving video files.
            string vidPath = @"C:\VideoClips";

            if (Directory.Exists(vidPath) == false)
            {
                Directory.CreateDirectory(vidPath);
            }

            // Create directory for saving image files.
            string imgPath = @"C:\WebcamSnapshots";

            if (Directory.Exists(imgPath) == false)
            {
                Directory.CreateDirectory(imgPath);
            }

            // Set some properties of the Webcam control
            WebCamCtrl.VideoDirectory = vidPath;
            WebCamCtrl.VidFormat = VideoFormat.mp4;

            WebCamCtrl.ImageDirectory = imgPath;
            WebCamCtrl.PictureFormat = ImageFormat.Jpeg;
                        
            WebCamCtrl.FrameRate = 30;
            WebCamCtrl.FrameSize = new System.Drawing.Size(320, 240);          

            // Find a/v devices connected to the machine.
            FindDevices();

            VidDvcsComboBox.SelectedIndex = 0;
            AudDvcsComboBox.SelectedIndex = 0;
        }

        private void FindDevices()
        {
            var vidDevices = EncoderDevices.FindDevices(EncoderDeviceType.Video);
            var audDevices = EncoderDevices.FindDevices(EncoderDeviceType.Audio);

            foreach (EncoderDevice dvc in vidDevices)
            {
                VidDvcsComboBox.Items.Add(dvc.Name);
            }

            foreach (EncoderDevice dvc in audDevices)
            {
                AudDvcsComboBox.Items.Add(dvc.Name);
            }

        }

        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Display webcam video on control.
                WebCamCtrl.StartCapture();               
            }
            catch (Microsoft.Expression.Encoder.SystemErrorException ex)
            {
                MessageBox.Show("Device is in use by another application");
            }
        }

        private void EndButton_Click(object sender, RoutedEventArgs e)
        {
            // Stop the display of webcam video.
            WebCamCtrl.StopCapture();
        }

        private void RecordButton_Click(object sender, RoutedEventArgs e)
        {
            // Start recording of webcam video to harddisk.
            WebCamCtrl.StartRecording();
        }

        private void StopRecordButton_Click(object sender, RoutedEventArgs e)
        {
            // Stop recording of webcam video to harddisk.
            WebCamCtrl.StopRecording();
        }

        private void SnapshotButton_Click(object sender, RoutedEventArgs e)
        {
            // Take snapshot of webcam image.
            WebCamCtrl.TakeSnapshot();
        }           
       
    }
}

As you can see from the sample code using the Webcam control is not a hard affair once you have the necessary references and using/Imports statements.

Webcam

The following are the members of interest in class Webcam,

Properties

Name Description Type
WPF_WebcamControl/PropertyIcon.png VideoDirectory Gets or Sets the folder where the recorded webcam video will be saved. This is a dependency property. String
WPF_WebcamControl/PropertyIcon.png VidFormat Gets or Sets the video format in which the webcam video will be saved. This is a dependency property. (The default format is .wmv) VideoFormat
WPF_WebcamControl/PropertyIcon.png VideoDevice Gets or Sets the name of the video device to be used. This is a dependency property. String
WPF_WebcamControl/PropertyIcon.png AudioDevice Gets or Sets the name of the audio device to be used. This is a dependency property. String
WPF_WebcamControl/PropertyIcon.png IsRecording Gets a value indicating whether video recording is taking place. This is a read-only property. Boolean
WPF_WebcamControl/PropertyIcon.png ImageDirectory Gets or Sets the folder where a snapshot of the webcam video will be saved. This is a dependency property. String
WPF_WebcamControl/PropertyIcon.png PictureFormat Gets or Sets the format in which a snapshot of the webcam video will be saved. This is a dependency property. (The default format is Jpeg). ImageFormat
WPF_WebcamControl/PropertyIcon.png FrameRate Gets or sets the frame rate in frames per second. This is a dependency property. (The default value is 15). Integer
WPF_WebcamControl/PropertyIcon.png FrameSize Gets or sets the size of the video profile. This is a dependency property. (The default size is 320x240). System.Drawing.Size

Methods

Name Description
WPF_WebcamControl/MethodIcon.png StartCapture Displays webcam video on control. (Throws a Microsoft.Expression.Encoder.SystemErrorException if a specified device is already in use by another application)
WPF_WebcamControl/MethodIcon.png StopCapture Stops the capturing/display of webcam video. (Stops any current recording of webcam video)
WPF_WebcamControl/MethodIcon.png StartRecording Starts the recording of webcam video to a video file. (Throws a DirectoryNotFoundException if the directory specified in the VideoDirectory property does not exist)
WPF_WebcamControl/MethodIcon.png StopRecording Stops the recording of webcam video.  
WPF_WebcamControl/MethodIcon.png TakeSnapshot Saves a snapshot of the webcam video. (Throws a DirectoryNotFoundException if the directory specified in the ImageDirectory property does not exist)

The Code

The XAML markup for the UserControl is,

<UserControl x:Class="Webcam" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             Height="Auto" Width="Auto" MinHeight="100" MinWidth="100" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
             mc:Ignorable="d" d:DesignWidth="320" d:DesignHeight="240" Name="Webcam">
    <Grid>
        <WindowsFormsHost Margin="0,0,0,0" Name="WinFormHost" Background="{x:Null}">
            <wf:Panel x:Name="WebcamPanel" Size="320,240" />
        </WindowsFormsHost>
    </Grid>
</UserControl>
The VideoDevice dependency property is defined as follows,

''' <summary>
''' Gets or Sets the name of the video device to be used.
''' </summary>    
Public Property VideoDevice() As String
    Get
        Return CType(GetValue(VideoDeviceProperty), String)
    End Get
    Set(ByVal value As String)
        SetValue(VideoDeviceProperty, value)
    End Set
End Property

Public Shared VideoDeviceProperty As DependencyProperty = _
    DependencyProperty.Register("VideoDevice", GetType(String), GetType(Webcam), _
                          New FrameworkPropertyMetadata(New PropertyChangedCallback( _
                                                              AddressOf VidDeviceChange)))

Private Shared Sub VidDeviceChange(ByVal source As DependencyObject, _
    ByVal e As DependencyPropertyChangedEventArgs)
    Dim deviceName As String = CType(e.NewValue, String)
    Dim eDev = EncoderDevices.FindDevices(EncoderDeviceType.Video).Where _
               (Function(dv) dv.Name = deviceName)

    If (eDev.Count > 0) Then
        CType(source, Webcam).vidDevice = eDev.First

        Try
            CType(source, Webcam).Display()
        Catch ex As Microsoft.Expression.Encoder.SystemErrorException
            Exit Sub
        End Try
    End If
End Sub

The StartCapture() method displays the webcam video in the WinForm Panel, if the necessary properties are set,

''' <summary>
''' Display webcam video on control.
''' </summary>
Public Sub StartCapture()
    If (canCapture = False) Then
        canCapture = True

        Try
            Display()
        Catch ex As Microsoft.Expression.Encoder.SystemErrorException
            canCapture = False
            Throw New Microsoft.Expression.Encoder.SystemErrorException
        End Try
    Else
        Exit Sub
    End If
End Sub
    
' Display video from webcam.
Private Sub Display()
    If (canCapture = True) Then
        If (vidDevice IsNot Nothing) Then
            StopRecording()
            Dispose()

            job = New LiveJob
            Dim frameDuration As Long = CLng(_frameRate * Math.Pow(10, 7))

            deviceSource = job.AddDeviceSource(vidDevice, audDevice)
            deviceSource.PickBestVideoFormat(_frameSize, frameDuration)
            WebcamPanel.Size = _frameSize
            job.OutputFormat.VideoProfile.Size = _frameSize
            deviceSource.PreviewWindow = New PreviewWindow(New HandleRef(WebcamPanel, WebcamPanel.Handle))

            job.ActivateSource(deviceSource)

            isCapturing = True
        End If
    End If
End Sub

The StartRecording() method records video from the webcam to the harddisk,

''' <summary>
''' Starts the recording of webcam video to a video file.
''' </summary>
Public Sub StartRecording()
    If (vidDirectory <> String.Empty AndAlso job IsNot Nothing) Then
        If (Directory.Exists(vidDirectory) = False) Then
            Throw New DirectoryNotFoundException("The specified directory does not exist")
            Exit Sub
        End If

        ' If isCapturing is true then it means the control is capturing images 
        ' from the webcam.
        If (isCapturing = True) Then
            StopRecording()
            job.PublishFormats.Clear()

            Dim timeStamp As String = DateTime.Now.ToString
            timeStamp = timeStamp.Replace("/", "-")
            timeStamp = timeStamp.Replace(":", ".")
            Dim filePath As String = vidDirectory & "\WebcamVid " & timeStamp & "." & _vidFormat.ToString

            Dim fileArchFormat As New FileArchivePublishFormat(filePath)
            job.PublishFormats.Add(fileArchFormat)
            job.StartEncoding()

            _isRecording = True
        End If
    End If
End Sub

The VideoFormat enumeration contains three members,

Public Enum VideoFormat
    wmv
    mp4
    flv
End Enum

The TakeSnapshot() method saves a snapshot of the webcam video. The image generated is actually a snapshot of the WinForms Panel, WebcamPanel. The size of the image will depend on the size of the Webcam control.

''' <summary>
''' Take snapshot of a webcam image. 
''' </summary>
Public Sub TakeSnapshot()
    If (imgDirectory <> String.Empty AndAlso job IsNot Nothing) Then
        If (Directory.Exists(imgDirectory) = False) Then
            Throw New DirectoryNotFoundException("The specified directory does not exist")
            Exit Sub
        End If

        ' If isCapturing is true then it means the control is capturing video 
        ' from the webcam.
        If (isCapturing = True) Then
            Dim panelWidth As Integer = CInt(Me.ActualWidth)
            Dim panelHeight As Integer = CInt(Me.ActualHeight)

            Dim timeStamp As String = DateTime.Now.ToString
            timeStamp = timeStamp.Replace("/", "-")
            timeStamp = timeStamp.Replace(":", ".")

            Dim filePath As String = imgDirectory & "\Snapshot " & timeStamp & "." & imgFormat.ToString

            Dim pnlPnt As Point = WebcamPanel.PointToScreen(New Point(WebcamPanel.ClientRectangle.X, _
                                                                      WebcamPanel.ClientRectangle.Y))

            Using bmp As New Bitmap(panelWidth, panelHeight)
                Using gcs As Graphics = Graphics.FromImage(bmp)
                    gcs.CopyFromScreen(pnlPnt, Point.Empty, New Size(panelWidth, panelHeight))
                End Using
                bmp.Save(filePath, imgFormat)
            End Using
        End If
    End If
End Sub

You can take a look at the other properties and methods defined in class Webcam by downloading the source files from the download link at the top of this article.

Conclusion

I hope that you picked up something useful from this article. I'm a novice in audio-video-encoding-decoding matters so if you have any questions regarding such technicalities, please try to post them in the associated forums here on CodeProject. Suggestions will be beneficial, as well as answers you receive to any technical queries that may be associated with this article's content. Thanks.

History

  • 18th Nov, 2011: Initial post
  • 19th Nov, 2011: Updated code
  • 31st Mar, 2012: Added snapshot feature.
  • 17th Nov, 2012: Added FrameRate and FrameSize properties.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Meshack Musundi
Software Developer
Kenya Kenya
Member
Meshack is an avid programmer with a bias towards WPF and VB.NET. He currently resides in a small town in Kiambu county, Kenya.
 
Awards;
  • CodeProject MVP 2013
  • CodeProject MVP 2012
  • Best VB.NET article of February 2013
  • Best VB.NET article of October 2012
  • Best VB.NET article of July 2012
  • Best VB.NET article of February 2012
  • Best VB.NET article of January 2012
  • Best VB.NET article of November 2011
  • Best VB.NET article of June 2011
  • Best VB.NET article of May 2011
  • Best VB.NET article of March 2011
  • Best VB.NET article of February 2011
  • Best VB.NET article of January 2011
  • Best VB.NET article of December 2010
  • Best VB.NET article of November 2010

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to get bytes after TakeSnapshotmemberdineshema19hrs 28mins ago 
Hi, I'm using .net 4.0 and visual studio 2010. I'm trying take picture from webcam using your webcam control. First thanks for your application. When i'm take a snap it is stored as a file. but i didn't want that. I want return snap image as bytes. So please help me for this.
Dinesh Kumar.Y
@Web Developer

QuestionVideo is pixelated and freezesmemberadrianmatteo7 May '13 - 18:18 
Hi, I'm using this library for a project and I'm trying to use a Microsoft Lifecam 3000 HD, but the video looks pixalated (The camera is 720p) and after 2-3 seconds it freezes a litle and the goes on. How can I record HD videos.
AnswerRe: Video is pixelated and freezesmvpMeshack Musundi11 May '13 - 7:07 
What values have you specified for the FrameSize property of the control?
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

QuestionThe name "Webcam" does not exist in the namespacememberTy Morrow25 Apr '13 - 18:48 
Here's the thing: it works fine, but I am getting an error that is causing my markup to be invalid.
 
The error I'm getting is:
Error 1: The name "Webcam" does not exist in the namespace
 
Anyone encounter and solve this?
QuestionPanel.ZIndex is not workingmemberoren_david23 Apr '13 - 10:52 
Hello,
first I'd like to thank you for this great project and for sharing it,
Everything is working great with this control, just 1 thing I can't manage to do,
I'd like to display the camera windows under a .PNG, usually I do it using Panel.ZIndex, But the ZIndex has no effect on the camera control.
Any idea??
 
Thanks,
David
AnswerRe: Panel.ZIndex is not workingmvpMeshack Musundi23 Apr '13 - 20:59 
Hi David. The reason ZIndex has no effect is because the webcam control makes use of a WinForms Panel. A hosted WinForms control is always drawn on top of WPF elements since the control is drawn in a separate HWND. A solution would be to place the .PNG image in a Popup as suggested by Shaun Fletcher here.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

QuestionHow to overlay this webcam control with an image?memberBreaka22 Apr '13 - 9:49 
I have a project and I have to overlay a part of the camera with an image
AnswerRe: How to overlay this webcam control with an image?mvpMeshack Musundi22 Apr '13 - 20:05 
This suggestion will be helpful; Re: Is it possible to move the Webcam Control behind my UI elements[^]
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

GeneralMy vote of 5memberamie106217 Apr '13 - 22:28 
well written and good documentation
GeneralRe: My vote of 5mvpMeshack Musundi22 Apr '13 - 20:06 
Thanks. Smile | :)
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

QuestionTwo cameras with same name(manufacturer) not workingmemberMember 798649417 Apr '13 - 6:10 
hi,
I have two cameras of same manufacturer. Their names read by application is 'USB Video Camera'. But the application reads only one camera might be because they have same name.
 
How to resolve this. I want to use both the cameras.
QuestionPause in Recodingmembersdimka11 Apr '13 - 23:54 
Hi, Meshack!
Thank you very much for such a great job!
I have a little question. Is it possible somehow to make a pause while recording? So that a video would not contain a part that was paused, but still be stored in a single file.
AnswerRe: Pause in RecodingmvpMeshack Musundi12 Apr '13 - 3:19 
sdimka wrote:
Is it possible somehow to make a pause while recording? So that a video would not contain a part that was paused, but still be stored in a single file
No, it's not possible.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

QuestionWebcam is showing black screen in previewmemberMember 79864944 Apr '13 - 2:08 
I downloaded the application. It is working great!. But it works only for 4 times. Fifth time when I click on Preview button, it shows black screen in preview window. If I close the application and run it again then it works. but only 4 times. It does not work continuously.

Please help. It's an urgent.
AnswerRe: Webcam is showing black screen in previewmvpMeshack Musundi4 Apr '13 - 10:52 
I have no idea why you are experiencing that issue. I ran the app and started and stopped the preview more than six times without any issue.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

GeneralRe: Webcam is showing black screen in previewmemberMember 79864944 Apr '13 - 23:35 
I have 2 cameras connected to my pc. I select camera1 from the list then click Start Capture and then End Capture. Then I select camera2. This way it works 4 times. 5th time it shows black screen.
 
I am developing one application where I need to use 2 cameras. I put breakpoint also in Display() method. no error. Everything is going fine. All values are same as like first 4 transactions. I used GC.Collect() also. But I get preview as black screen.
 
This is happening on Development machine. May be I will try on Production machine.
 
Anyway thanks for your reply.
GeneralRe: Webcam is showing black screen in previewmemberMember 79864948 Apr '13 - 0:56 
ok. It is not working on development machine. But on production machine it is working like a charm!!!
QuestionControl to view webcam imagesmemberwendysimvining23 Mar '13 - 4:52 
What control do u use on the designer to view the webcam image? Image? mediaElements?
AnswerRe: Control to view webcam imagesmvpMeshack Musundi23 Mar '13 - 6:21 
WinForms Panel.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

QuestionQuestion regarding c920 camera and also framesizesmemberShaun T Fletcher22 Mar '13 - 21:38 
Hi meshack.
 
many many thanks for this it has been a huge help with a big project.
 
I have encountered a problem with the logitech C920 (this is the current prime market cam for them) on windows 7, in that it always reports as in use already. all older logitech models work fine, and the c920 works fine on windows 8. Any thoughts?
 
Additionally I want to display the video on a control of fixed size, but capture images at the installed camera's maximum frame size. Is there any way to query the installed camera for its available image size, and can I display the live camera feed on a smaller wpf control but still capture images at the full resolution?
 
Regards and again thanks.
AnswerRe: Question regarding c920 camera and also framesizesmvpMeshack Musundi23 Mar '13 - 6:17 
Shaun T Fletcher wrote:
I have encountered a problem with the logitech C920 (this is the current prime market cam for them) on windows 7, in that it always reports as in use already. all older logitech models work fine, and the c920 works fine on windows 8. Any thoughts?
I'm not sure of the cause of this issue. Frown | :(
 
Shaun T Fletcher wrote:
Is there any way to query the installed camera for its available image size,
I'm guessing it may be possible but I currently don't know how you would be able to do this. If I figure it out I'll let you know.
 
Shaun T Fletcher wrote:
can I display the live camera feed on a smaller wpf control but still capture images at the full resolution?
Yes.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

GeneralRe: Question regarding c920 camera and also framesizesmemberShaun T Fletcher1 Apr '13 - 12:25 
Thanks.
 
We upgraded the units to windows 8 and the problem with the C920 went away by the way!
Questionbitratemembermartinmat22 Mar '13 - 11:08 
Can also be adjusted bitrate
AnswerRe: bitratemvpMeshack Musundi23 Mar '13 - 6:08 
Currently, no.
"As beings of finite lifespan, our contributions to the sum of human knowledge is one of the greatest endeavors we can undertake and one of the defining characteristics of humanity itself"

GeneralRe: bitrate + live stream win servermembermartinmat23 Mar '13 - 23:16 
Indeed, this application is great.
I tried the live stream on the window server and failed. Da is here complete instructions How to live stream?
In the discussion I found your code, but it does not work ...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 11 Feb 2013
Article Copyright 2011 by Meshack Musundi
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid