以下是一个示例代码,可以获取视频采集卡并实时显示到winform中:

using System;
using System.Drawing;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;

namespace VideoCaptureCard
{
    public partial class Form1 : Form
    {
        private FilterInfoCollection videoDevices;
        private VideoCaptureDevice videoSource;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 获取可用的视频采集设备
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

            // 将可用设备添加到下拉列表中
            foreach (FilterInfo device in videoDevices)
            {
                comboBox1.Items.Add(device.Name);
            }

            if (comboBox1.Items.Count > 0)
            {
                comboBox1.SelectedIndex = 0;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 选择视频采集设备
            videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
            videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);

            // 开始捕获
            videoSource.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // 停止捕获
            videoSource.Stop();
        }

        private void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            // 将新帧添加到PictureBox中显示
            pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();
        }
    }
}

在这个示例中,我们使用了AForge.NET框架来获取视频采集设备并实时显示到Winform中。在Form1_Load事件中,我们使用FilterInfoCollection类获取可用的视频采集设备并将它们添加到下拉列表中。在“开始”按钮的单击事件中,我们选择所选设备并开始捕获视频。在NewFrame事件中,我们将新帧添加到PictureBox控件中。在“停止”按钮的单击事件中,我们停止捕获视频

c# 获取视频采集卡并实时显示到winform中

原文地址: https://www.cveoy.top/t/topic/fi8G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录