i am developing a small application which capture video from web cam and save in my computer location.i have done some code but its not detecting the web cam.plz help me. thanks in advanced.
i am putting my code here.
Window1.xaml
<Window x:Class="AvCapWPF.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:l="clr-namespace:AvCapWPF"
Name="wnd"
Title="Window1" Height="291" Width="286">
<Window.Resources>
<l:ScaleConverter x:Key="conv"/>
</Window.Resources>
<Grid>
<l:CapPlayer x:Name="player" RenderTransformOrigin="0.5,0.5">
<l:CapPlayer.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="180.294"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</l:CapPlayer.RenderTransform>
</l:CapPlayer>
<HeaderedItemsControl Header="Framerate" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="55">
<Grid>
<Rectangle Fill="#55FF0000">
<Rectangle.Height>
<MultiBinding Converter="{StaticResource conv}">
<Binding ElementName="player" Path="Framerate"/>
<Binding ElementName="wnd" Path="ActualHeight"/>
</MultiBinding>
</Rectangle.Height>
</Rectangle>
<TextBlock Text="{Binding ElementName=player, Path=Framerate}" HorizontalAlignment="Left" Width="13" />
</Grid>
</HeaderedItemsControl>
<Button Height="23" Name="btnStart" VerticalAlignment="Bottom" Margin="0,0,74,0" Click="btnStart_Click" HorizontalAlignment="Right" Width="61">Start</Button>
<Button Height="23" Margin="0,0,8,0" Name="button2" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="61">Stop</Button>
<Button Height="23" Margin="74,0,0,0" Name="btnCue" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="48" Click="btnCue_Click">cue</Button>
</Grid>
</Window
>
window1.xaml.cs
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 DirectX.Capture;
namespace AvCapWPF
{
public partial class Window1 : Window
{
private Capture capture = null;
public Window1()
{
InitializeComponent();
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
try
{
}
catch (Exception ex)
{
MessageBox.Show("Unable to enable/disable preview. Please submit a bug report.\n\n" + ex.Message + "\n\n" + ex.ToString());
}
try
{
if (capture == null)
throw new ApplicationException("Please select a video and/or audio device.");
if (!capture.Cued)
capture.Filename = "D:\anay.avi";
capture.Start();
btnCue.IsEnabled = false;
btnStart.IsEnabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.ToString());
}
}
private void btnCue_Click(object sender, RoutedEventArgs e)
{
try
{
if (capture == null)
throw new ApplicationException("Please select a video and/or audio device.");
if (!capture.Cued)
capture.Filename = "D:\anay.avi";
capture.Cue();
btnCue.IsEnabled = false;
MessageBox.Show("Ready to capture.\n\nUse Cue() before Start() to " +
"do all the preparation work that needs to be done to start a " +
"capture. Now, when you click Start the capture will begin faster " +
"than if you had just clicked Start. Using Cue() is completely " +
"optional. The downside to using Cue() is the preview is disabled until " +
"the capture begins.");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n\n" + ex.ToString());
}
}
}
public class ScaleConverter : IMultiValueConverter
{
#region IMultiValueConverter Members
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
float v = (float)values[0];
double m = (double)values[1];
return v * m / 50;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
}