WPF使用AForge呼叫攝像頭
阿新 • 來源:網路 • 發佈:2022-01-31
AForge引用
1.建立WPF專案,在NuGet安裝AForge相關SDK包:

2.專案引用
2.1.由於在WPF當中使用AForge,需要通過WindowsFormsHost嵌入在WPF當中使用,所以需要給專案新增相關引用:

2.2.頁面新增名稱空間
.xaml檔案中,新增以下名稱空間:
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:aforge="clr-namespace:AForge.Controls;assembly=AForge.Controls
3.建立控制元件
為XAML中新增一個WindowsFormsHoscLtSNIwQwVt 嵌入一個VideoSourcePlayer
<wfi:WindowsFormsHost > <aforge:VideoSourcePlayer x:Name="player" Dock="Fill" /> </wfi:WindowsFormsHost>
初始化
在後臺程式碼中,新增初始化程式碼,以下程式碼模擬設定的第一個攝像頭,FilterInfoCollection實際為一個集合。
FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count > 0)
{
var videoDevice = new VideoCacLtSNIwQwVptureDevice(videoDevices[0].MonikerString);
videoDevice.VideoResolution = videoDevice.VideoCapabilities[0]; //設定解析度
player.VideoSource = videoDevice; //設定源
player.Start(); //啟動
}實際效果(演示):

拍照
player.GetCurrentVideoFrame();
到此這篇關於WPF使用AForge呼叫攝像頭的www.cppcns.com文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支援我們。
