728x90
반응형
728x170
※ 웹 카메라 캡처 부분을 캡처할 수 없었다.
[TestProject 프로젝트]
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:library="clr-namespace:TestLibrary;assembly=TestLibrary"
Width="800"
Height="600"
MinWidth="400"
MinHeight="300"
Title="웹 카메라 사용하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border Grid.Row="0"
BorderThickness="1"
BorderBrush="Black">
<library:WebCameraControl x:Name="webCameraControl" />
</Border>
<StackPanel Grid.Row="2"
Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<ComboBox x:Name="videoCaptureDeviceComboBox"
Margin="0 5 0 5"
Width="200"
Height="30"
VerticalContentAlignment="Center"
DisplayMemberPath="Name" />
<Button x:Name="startButton"
Margin="20 5 0 5"
Width="100"
Height="30"
IsEnabled="True"
Content="시작하기" />
<Button x:Name="stopButton"
Margin="10 5 0 5"
Width="100"
Height="30"
Content="중단하기"
IsEnabled="{Binding Path=IsCapturing, ElementName=webCameraControl}" />
<Button x:Name="imageButton"
Margin="10 5 0 5"
Width="100"
Height="30"
Content="이미지"
IsEnabled="{Binding Path=IsCapturing, ElementName=webCameraControl}" />
</StackPanel>
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using Microsoft.Win32;
using System.Windows;
using System.Windows.Controls;
using TestLibrary;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
this.videoCaptureDeviceComboBox.ItemsSource = this.webCameraControl.GetVideoCaptureDeviceList();
if(this.videoCaptureDeviceComboBox.Items.Count > 0)
{
this.videoCaptureDeviceComboBox.SelectedItem = this.videoCaptureDeviceComboBox.Items[0];
}
this.videoCaptureDeviceComboBox.SelectionChanged += videoCaptureDeviceComboBox_SelectionChanged;
this.startButton.Click += startButton_Click;
this.stopButton.Click += stopButton_Click;
this.imageButton.Click += imageButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 비디오 캡처 장치 콤보 박스 선택 변경시 처리하기 - videoCaptureDeviceComboBox_SelectionChanged(sender, e)
/// <summary>
/// 비디오 캡처 장치 콤보 박스 선택 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void videoCaptureDeviceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
this.startButton.IsEnabled = e.AddedItems.Count > 0;
}
#endregion
#region 시작하기 버튼 클릭시 처리하기 - startButton_Click(sender, e)
/// <summary>
/// 시작하기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void startButton_Click(object sender, RoutedEventArgs e)
{
VideoCaptureDevice videoCaptureDevice = (VideoCaptureDevice)this.videoCaptureDeviceComboBox.SelectedItem;
this.webCameraControl.StartCapture(videoCaptureDevice);
this.startButton.IsEnabled = false;
}
#endregion
#region 중단하기 버튼 클릭시 처리하기 - startButton_Click(sender, e)
/// <summary>
/// 중단하기 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void stopButton_Click(object sender, RoutedEventArgs e)
{
this.webCameraControl.StopCapture();
this.startButton.IsEnabled = true;
}
#endregion
#region 이미지 버튼 클릭시 처리하기 - startButton_Click(sender, e)
/// <summary>
/// 이미지 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void imageButton_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = "비트맵 이미지|*.bmp" };
if(saveFileDialog.ShowDialog() == true)
{
this.webCameraControl.GetCurrentImage().Save(saveFileDialog.FileName);
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] 가상 키보드 사용하기 (0) | 2019.06.23 |
---|---|
[C#/WPF] BlurEffect 클래스 사용하기 (0) | 2019.06.22 |
[C#/WPF] 커스텀 컨트롤 만들기 (0) | 2019.06.22 |
[C#/WPF] 반투명 윈도우 사용하기 (0) | 2019.06.16 |
[C#/WPF] 실시간 스트리밍 프토로콜(RTSP)을 사용해 동영상 재생하기 (0) | 2019.06.15 |
[C#/WPF] 반투명 윈도우 사용하기 (0) | 2019.06.10 |
[C#/WPF] TreeView 클래스 : 데이터 바인딩시 부모 노드 사전 설정하기 (0) | 2019.06.02 |
[C#/WPF] TreeView 클래스 : ItemContainerGenerator 속성을 사용해 바인딩 데이터의 트리 노드 구하기 (0) | 2019.06.02 |
[C#/WPF] ComponentDispatcher 클래스 : ThreadFilterMessage 정적 이벤트를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
[C#/WPF] HwndSource 클래스 : AddHook 메소드를 사용해 윈도우 이벤트 가로채기 (0) | 2019.06.02 |
댓글을 달아 주세요