< StackPanel Orientation ="Vertical" VerticalAlignment ="Center"
HorizontalAlignment ="Center" >
< Rectangle Width ="320" Height ="240" x:Name ="videoRect" />
< StackPanel Orientation ="Horizontal" HorizontalAlignment ="Center" >
< ListBox x:Name ="VideoSources" >
< ListBox.ItemTemplate >
< DataTemplate >
< TextBlock Text ="{Binding FriendlyName}" />
</ DataTemplate >
</ ListBox.ItemTemplate >
</ ListBox >
< ListBox x:Name ="AudioSources" >
< ListBox.ItemTemplate >
< DataTemplate >
< TextBlock Text ="{Binding FriendlyName}" />
</ DataTemplate >
</ ListBox.ItemTemplate >
</ ListBox >
</ StackPanel >
< StackPanel Orientation ="Horizontal" HorizontalAlignment ="Center" >
< Button Margin ="5" Content =" " x:Name ="startCapture" />
< Button Margin ="5" Content =" " x:Name ="endCapture" />
</ StackPanel >
</ StackPanel >
* This source code was highlighted with Source Code Highlighter .
this .Loaded += new RoutedEventHandler(MainPage_Loaded);
* This source code was highlighted with Source Code Highlighter .
void MainPage_Loaded( object sender, RoutedEventArgs e)
{
VideoSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();
AudioSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices();
}
* This source code was highlighted with Source Code Highlighter .
private CaptureSource _captureSource;
* This source code was highlighted with Source Code Highlighter .
_captureSource = new CaptureSource();
* This source code was highlighted with Source Code Highlighter .
private void startCapture_Click( object sender, RoutedEventArgs e)
{
if (_captureSource != null )
{
_captureSource.Stop();
_captureSource.VideoCaptureDevice = (VideoCaptureDevice)VideoSources.SelectedItem;
_captureSource.AudioCaptureDevice = (AudioCaptureDevice)AudioSources.SelectedItem;
VideoBrush vidBrush = new VideoBrush();
vidBrush.SetSource(_captureSource);
videoRect.Fill = vidBrush;
if (CaptureDeviceConfiguration.AllowedDeviceAccess ||
CaptureDeviceConfiguration.RequestDeviceAccess())
{
_captureSource.Start();
}
}
}
* This source code was highlighted with Source Code Highlighter .
private void endCapture_Click( object sender, RoutedEventArgs e)
{
if (_captureSource != null )
{
_captureSource.Stop();
}
}
* This source code was highlighted with Source Code Highlighter .
public partial class MainPage : UserControl
{
private CaptureSource _captureSource;
public MainPage()
{
InitializeComponent();
this .Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded( object sender, RoutedEventArgs e)
{
VideoSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();
AudioSources.ItemsSource = CaptureDeviceConfiguration.GetAvailableAudioCaptureDevices();
_captureSource = new CaptureSource();
}
private void startCapture_Click( object sender, RoutedEventArgs e)
{
if (_captureSource != null )
{
_captureSource.Stop();
_captureSource.VideoCaptureDevice = (VideoCaptureDevice)VideoSources.SelectedItem;
_captureSource.AudioCaptureDevice = (AudioCaptureDevice)AudioSources.SelectedItem;
VideoBrush vidBrush = new VideoBrush();
vidBrush.SetSource(_captureSource);
videoRect.Fill = vidBrush;
if (CaptureDeviceConfiguration.AllowedDeviceAccess ||
CaptureDeviceConfiguration.RequestDeviceAccess())
{
_captureSource.Start();
}
}
}
private void endCapture_Click( object sender, RoutedEventArgs e)
{
if (_captureSource != null )
{
_captureSource.Stop();
}
}
}
* This source code was highlighted with Source Code Highlighter .
< Button Margin ="5" Content ="Snapshot" x:Name ="takeSnapshot" Click ="takeSnapshot_Click" />
* This source code was highlighted with Source Code Highlighter .
< ScrollViewer Width ="400" VerticalScrollBarVisibility ="Hidden" HorizontalScrollBarVisibility ="Auto"
HorizontalAlignment ="Center" >
< ItemsControl x:Name ="snapshots" >
< ItemsControl.ItemTemplate >
< DataTemplate >
< Image Source ="{Binding}" Margin ="5" Height ="50" Stretch ="UniformToFill" ></ Image >
</ DataTemplate >
</ ItemsControl.ItemTemplate >
< ItemsControl.ItemsPanel >
< ItemsPanelTemplate >
< StackPanel Orientation ="Horizontal" />
</ ItemsPanelTemplate >
</ ItemsControl.ItemsPanel >
</ ItemsControl >
</ ScrollViewer >
* This source code was highlighted with Source Code Highlighter .
private ObservableCollection<WriteableBitmap> _images = new ObservableCollection<WriteableBitmap>();
* This source code was highlighted with Source Code Highlighter .
private void takeSnapshot_Click( object sender, RoutedEventArgs e)
{
if (_captureSource != null )
{
_captureSource.AsyncCaptureImage((snapImage) =>
{
_images.Add(snapImage);
});
}
}
* This source code was highlighted with Source Code Highlighter .
snapshots.ItemsSource = _images;
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/75744/