Я хочу интегрировать веб-камеру, и я использую Aforge.NET Framework.Какой контроль мне нужен, чтобы показать видео с веб-камеры.Моя простая программа получит веб-камеру, поместит ее в поле со списком, и когда я нажимаю «ОК», я вижу, что камера работает, но я не вижу видео.C # / WPF
`
<Window x:Class="MyWebCam.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="425">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="4*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.ColumnSpan="2" x:Name="videoPlayer" Margin="15"></Image>
<ComboBox Grid.Row="1" Grid.ColumnSpan="2" x:Name="cbxDevices" MinWidth="150" Margin="15" VerticalAlignment="Center" HorizontalAlignment="left" SelectionChanged="cbxDevices_SelectionChanged" />
<Button Grid.Column="1" Grid.Row="1" x:Name="btnOk" Content="OK" MinWidth="100" Margin="15" Click="btnOk_Click" />
</Grid>
</Window>
`
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 AForge;
using AForge.Imaging;
using AForge.Video;
using AForge.Video.VFW;
using AForge.Video.DirectShow;
using AForge.Controls;
using System.Drawing;
using AForge.Vision.Motion;
using AForge.Vision;
namespace MyWebCam
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
//opened video source
private VideoCaptureDevice videoSource = null;
//motion detector
MotionDetector detector = new MotionDetector(
new TwoFramesDifferenceDetector(),
new MotionAreaHighlighting());
FilterInfoCollection videoDevices;
private bool deviceExist = false;
private string device;
//video device
public string VideoDevice
{
get { return device; }
}
public MainWindow()
{
InitializeComponent();
getCamList();
}
private void getCamList()
{
try
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
cbxDevices.Items.Clear();
if (videoDevices.Count == 0)
{
throw new ApplicationException();
}
deviceExist = true;
foreach (FilterInfo device in videoDevices)
{
cbxDevices.Items.Add(device.Name);
}
cbxDevices.SelectedIndex = 0; //make first cam default
}
catch (ApplicationException)
{
deviceExist = false;
cbxDevices.Items.Add("No webcams on your system");
}
}
private void cbxDevices_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
device = videoDevices[cbxDevices.SelectedIndex].MonikerString;
if (cbxDevices.SelectedIndex != -1)
{
videoSource = new VideoCaptureDevice(videoDevices[cbxDevices.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
}
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
// get new frame
Bitmap video = (Bitmap)eventArgs.Frame;
// process the frame
videoPlayer.Source = video; //this is where i'm having the problem
}
private void btnOk_Click(object sender, RoutedEventArgs e)
{
videoSource.Start();
}
}
}