Click here to Skip to main content
16,004,479 members

Comments by FearfulSymmetry (Top 3 by date)

FearfulSymmetry 16-Nov-12 11:09am View    
Ok! I will try writing one. Thanks for the advice.
FearfulSymmetry 16-Nov-12 10:52am View    
You are right that I should learn VB.NET or C# but I have no where to learn it. No programming classes are offered at my school and I have searched the net over for help but have found no straight answers. If you know where I can go or have any sources that would help, please share. If not, here is the C# code.


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
{
///
/// Interaction logic for MainWindow.xaml
///

public partial class MainWindow : Window
{
private Webcam webCamCtrl;

public MainWindow()
{
InitializeComponent();

webCamCtrl = new Webcam();

// 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.wmv;

webCamCtrl.ImageDirectory = imgPath;
webCamCtrl.PictureFormat = ImageFormat.Jpeg;

// Set the Webcam control as the ContentControl's content.
ContentControl1.Content = webCamCtrl;

// 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 StopRecord
FearfulSymmetry 22-Oct-12 19:59pm View    
Thank you!