• 大小: 0.23M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-25
  • 语言: C#
  • 标签: 打印  

资源简介


资源截图

代码片段和文件信息

using AForge.Video.DirectShow;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AforgeDemo
{
    public partial class Form1 : Form
    {
        private FilterInfoCollection videoDevices;//所有摄像设备
        private VideoCaptureDevice videoDevice;//摄像设备
        private VideoCapabilities[] videoCapabilities;//摄像头分辨率
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);//得到机器所有接入的摄像设备
            if (videoDevices.Count != 0)
            {
                foreach (FilterInfo device in videoDevices)
                {
                    cboVideo.Items.Add(device.Name);//把摄像设备添加到摄像列表中
                }
            }
            else
            {
                cboVideo.Items.Add(“没有找到摄像头“);
            }
            cboVideo.SelectedIndex = 0;//默认选择第一个
        }

        private void cboVideo_SelectedIndexChanged(object sender EventArgs e)
        {
            if (videoDevices.Count != 0)
            {
                //获取摄像头
                videoDevice = new VideoCaptureDevice(videoDevices[cboVideo.SelectedIndex].MonikerString);
                GetDeviceResolution(videoDevice);//获得摄像头的分辨率
            }
        }
        //获得摄像头的分辨率
        private void GetDeviceResolution(VideoCaptureDevice videoCaptureDevice)
        {
            cboResolution.Items.Clear();//清空列表
            videoCapabilities = videoCaptureDevice.VideoCapabilities;//设备的摄像头分辨率数组
            foreach (VideoCapabilities capabilty in videoCapabilities)
            {
                //把这个设备的所有分辨率添加到列表
                cboResolution.Items.Add(“{capabilty.frameSize.Width} x {capabilty.frameSize.Height}“);
            }
            cboResolution.SelectedIndex = 0;//默认选择第一个
        }

        private void btnConnect_Click(object sender EventArgs e)
        {
            if (videoDevice != null)//如果摄像头不为空
            {
                if ((videoCapabilities != null) && (videoCapabilities.Length != 0))
                {
                    videoDevice.VideoResolution = videoCapabilities[cboResolution.SelectedIndex];//摄像头分辨率
                    vispShoot.VideoSource = videoDevice;//把摄像头赋给控件
                    vispShoot.Start();//开启摄像头
                    EnableControlStatus(false);
                }
            }
        }
        //控件的显示切换
        private void EnableControlStatus(bool status)
        {
            cboVideo.Enabled = status;
            cboResolution.Enabled = status;
            btnConnect.Enabled = status;
            btnPic.Enabled = !status;
            btnCut.Enabled = !status;
        }

        private void btnCut_Click(object sender EventArgs e)
        {
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-12-21 10:39  AforgeDemo\
     文件        5385  2019-02-27 14:18  AforgeDemo\AforgeDemo.csproj
     文件         909  2020-12-21 10:39  AforgeDemo\AforgeDemo.sln
     文件       19968  2020-12-21 10:39  AforgeDemo\AforgeDemo.suo
     目录           0  2019-02-27 14:16  AforgeDemo\bin\
     目录           0  2020-12-21 10:39  AforgeDemo\bin\Debug\
     文件       44544  2013-07-17 23:22  AforgeDemo\bin\Debug\AForge.Controls.dll
     文件       17920  2013-07-17 23:15  AforgeDemo\bin\Debug\AForge.dll
     文件      262656  2013-07-17 23:19  AforgeDemo\bin\Debug\AForge.Imaging.dll
     文件       68096  2013-07-17 23:17  AforgeDemo\bin\Debug\AForge.Math.dll
     文件       61440  2013-07-17 23:20  AforgeDemo\bin\Debug\AForge.Video.DirectShow.dll
     文件       20992  2013-07-17 23:20  AforgeDemo\bin\Debug\AForge.Video.dll
     文件       12288  2020-12-21 10:59  AforgeDemo\bin\Debug\AforgeDemo.exe
     文件       28160  2020-12-21 10:59  AforgeDemo\bin\Debug\AforgeDemo.pdb
     文件       11592  2020-12-21 11:00  AforgeDemo\bin\Debug\AforgeDemo.vshost.exe
     文件         490  2019-03-19 12:46  AforgeDemo\bin\Debug\AforgeDemo.vshost.exe.manifest
     文件        4137  2020-12-21 10:59  AforgeDemo\Form1.cs
     文件        7462  2020-12-21 10:59  AforgeDemo\Form1.Designer.cs
     文件        5817  2020-12-21 10:59  AforgeDemo\Form1.resx
     目录           0  2019-02-27 14:16  AforgeDemo\obj\
     目录           0  2020-12-21 10:59  AforgeDemo\obj\Debug\
     文件        1846  2020-12-21 11:00  AforgeDemo\obj\Debug\AforgeDemo.csproj.FileListAbsolute.txt
     文件         975  2020-12-21 10:59  AforgeDemo\obj\Debug\AforgeDemo.csproj.GenerateResource.Cache
     文件       12288  2020-12-21 10:59  AforgeDemo\obj\Debug\AforgeDemo.exe
     文件         180  2020-12-21 10:59  AforgeDemo\obj\Debug\AforgeDemo.Form1.resources
     文件       28160  2020-12-21 10:59  AforgeDemo\obj\Debug\AforgeDemo.pdb
     文件         180  2020-12-21 10:39  AforgeDemo\obj\Debug\AforgeDemo.Properties.Resources.resources
     文件       20602  2020-12-21 10:39  AforgeDemo\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6530  2020-12-21 10:59  AforgeDemo\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2019-02-27 14:16  AforgeDemo\obj\Debug\TempPE\
     文件         513  2019-02-27 14:18  AforgeDemo\packages.config
............此处省略7个文件信息

评论

共有 条评论