zoukankan      html  css  js  c++  java
  • 在WPF中使用AForge控件

    AForge.NET 是用C#写的一个关于计算机视觉和人工智能领域的框架,它包括图像处理、神经网络、遗传算法和机器学习等。

    要实现视频功能,需要使用AForge.Controls命名空间中的VideoSourcePlayer控件。这是一个WinForm控件,要在WPF程序中使用,我们需要做如下4步:

    1.添加WindowsFormsIntegration应用

    2.添加System.Windows.Forms.Integration命名空间

    xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
    

    3.添加AForge.Controls命名空间

     xmlns:aforge ="clr-namespace:AForge.Controls;assembly=AForge.Controls"

    4.XAML中加入VideoSourcePlayer可视控件

     <wfi:WindowsFormsHost Grid.Row="0" Height="320" Width="240">
         <aforge:VideoSourcePlayer x:Name="videoSourcePlayer" Dock="Fill">
         </aforge:VideoSourcePlayer>
     </wfi:WindowsFormsHost>
    

    VideoSourcePlayer控件需要先引用

    AForge.Controls.dll

    AForge.Video.dll

    AForge.Video.DirectShow.dll

    具体代码如下:

         public MainWindow()
            {
                InitializeComponent();
                videoSourcePlayer.NewFrame += VideoSourcePlayer_NewFrame;
                videoSourcePlayer.Height = 320;
                videoSourcePlayer.Width = 240;
            }
            private void VideoSourcePlayer_NewFrame(object sender, ref System.Drawing.Bitmap image)
            {
    
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                MJPEGStream mjpegSource = new MJPEGStream("http://192.168.191.1:8080");
                OpenVideoSource(mjpegSource);
            }
    
            private void OpenVideoSource(IVideoSource source)
            {
                videoSourcePlayer.SignalToStop();
                videoSourcePlayer.WaitForStop();
                videoSourcePlayer.VideoSource = source;
                videoSourcePlayer.Start();
            }
    
            private void Window_Unloaded(object sender, RoutedEventArgs e)
            {
                if (videoSourcePlayer.VideoSource != null)
                {
                    videoSourcePlayer.SignalToStop();
                    videoSourcePlayer.WaitForStop();
                }
            }
  • 相关阅读:
    html基本标签练习
    实践1-qq邮箱主页
    html加强
    Date日期操作
    日期类的加减及java中所以日期类的操作算法大全
    讲解java异常
    关于Java并发编程的总结和思考
    删除map、list集合元素总结
    Jedis使用总结【pipeline】【分布式的id生成器】【分布式锁【watch】【multi】】【redis分布式】
    Java中的时间日期处理
  • 原文地址:https://www.cnblogs.com/xienb/p/11109608.html
Copyright © 2011-2022 走看看