Some time ago, I wrote an article about how to capture images from a webcam. The article contained some customized code that was originally posted by Tamir Khason.
On January 7th, 2009, Edgar commented that he wanted to control the device or selected camera via WPF bindings. I agreed that if the blog entry promised to give a WPF Webcam Control, it should support WPF bindings as well.
So, I have rewritten some parts of the webcam control so that fully supports WPF. If have also written a simple sample application that allows users that download the control to easily decide whether this control is useful or not.
I have implemented code that you can easily change the MonikerString of a CapDevice. This means that you can set one device to a CapPlayer object and simply set the device via WPF bindings. The example application shows how to bind a combobox to the available devices on the system and how to set the values via dependency properties.
You can see a screenshot of the example application below:

Update (2011-01-13):
Recently, I received an e-mail from Haris Omeragic with an explanation on how to flip the image horizontally (both in the capture as preview). Here is the code he sent me:
<!-- Webcamp preview -->
<webcam:CapPlayer Grid.Row="2" x:Name="webcamPlayer" Stretch="Fill"
Rotation="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:PhotoCaptureView}}, Path=WebcamRotation}"
Height="{Binding ElementName=webcamPlayer, Path=ActualWidth, Converter={StaticResource ThreeFourthConverter}}"
Device="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:PhotoCaptureView}}, Path=SelectedWebcam}"
Style="{StaticResource DefaultCapPlayer}">
<webcam:CapPlayer.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="-1" ScaleY="1" />
<TranslateTransform X="{Binding ElementName=webcamPlayer, Path=ActualWidth}" Y="0" />
</TransformGroup>
</webcam:CapPlayer.RenderTransform>
</webcam:CapPlayer>
As you can see I added a RenderTransform element to the webcam control.
But, I also needed to flip the image itself before it's added to the SelectedImages collection:
private void CaptureImage_Executed(object sender, ExecutedRoutedEventArgs e)
{
//// Store current image in the webcam
BitmapSource bitmap = webcamPlayer.CurrentBitmap;
if (bitmap != null)
{
Transform tr = new System.Windows.Media.ScaleTransform(-1, 1);
var transformedBmp = new TransformedBitmap();
transformedBmp.BeginInit();
transformedBmp.Source = bitmap;
transformedBmp.Transform = tr;
transformedBmp.EndInit();
bitmap = transformedBmp;
SelectedImages.Add(bitmap);
}
}
WebcamPlayer_1.1.zip (118.49 kb) [Downloads: 8892]
Update (2011-11-03): I received an e-mail from Sylvain MAHE with the following comments:
When call Stop(), webcam is not released. (the Lamp of webcam not turned off)
Thred is Abort and the last action control.StopWhenReady(); is not called.
Update this file: CapDevice.cs (23.14 kb) [Downloads: 303]