资源简介

这次优化了界面初始化的按钮状态,以及随时录制视频的功能。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing.Imaging;
using System.Text;
using System.Windows;
using System.Windows.Forms;

//添加的
using System.IO;
using System.Windows.Media.Imaging;
using AForge;
using AForge.Controls;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Video.FFMPEG;
using Size = System.Drawing.Size;

namespace AforgeCameraOne
{
    public partial class Form1 : Form
    {
        private delegate void MyDelegateUI();//多线程问题
        private FilterInfoCollection videoDevices;  //摄像头设备  
        private VideoCaptureDevice videoSource;     //视频的来源选择  
        private VideoSourcePlayer videoSourcePlayer;    //AForge控制控件  
        private VideoFileWriter videoWriter=null;     //写入到视频  
        private bool is_record_video = false;   //是否开始录像  
        private bool is_multiPhotograph = false; //是否连续拍照 
        System.Drawing.Bitmap bmp1 = null;
        System.Timers.Timer timer_count;
        int tick_num = 0;
        int hour = 0;
        int i = 1;           //统计摄像头个数
        int width = 640;    //录制视频的宽度
        int height = 480;   //录制视频的高度
        int fps = 20;        //正常速率,fps越大速率越快,相当于快进

        public Form1()
        {
            InitializeComponent();
        }


        private void Form1_Load(object sender EventArgs e)
        {
            //初始化按钮状态
            btnClose.Enabled = false;
            btnPhotograph.Enabled = false;
            btnMultiPhotograph.Enabled = false;
            btnStarVideo.Enabled = false;
            btnPuaseVideo.Enabled = false;
            btnStopVideo.Enabled = false;

            try
            {
                // 枚举所有视频输入设备
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

                if (videoDevices.Count == 0)
                    throw new ApplicationException();

                foreach (FilterInfo device in videoDevices)
                {
                    
                    tscbxCameras.Items.Add(device.Name);
                    textBoxC.AppendText(“摄像头“ + i + “初始化完毕...“ + “\n“);
                    textBoxC.ScrollToCaret();
                    i++;
                }

                tscbxCameras.SelectedIndex = 0;

            }
            catch (ApplicationException)
            {
                tscbxCameras.Items.Add(“No local capture devices“);
                videoDevices = null;
            }
            //秒表
            timer_count = new System.Timers.Timer();   //实例化Timer类,设置间隔时间为1000毫秒;
            timer_count.Elapsed += new System.Timers.ElapsedEventHandler(tick_count);   //到达时间的时候执行事件;
            timer_count.AutoReset = true;   //设置是执行一次(false)还是一直执行(true);
            timer_count.Interval = 1000;
        }

        //计时器响应函数
        public void tick_count(object source System.Timers.ElapsedEventArgs e)
        {
            tick_num++;
     

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-10-13 22:14  AforgeCameraOne\
     目录           0  2017-10-17 09:41  AforgeCameraOne\AforgeCameraOne\
     文件        1014  2017-10-13 22:14  AforgeCameraOne\AforgeCameraOne.sln
     文件       47616  2017-10-17 09:43  AforgeCameraOne\AforgeCameraOne.v12.suo
     文件        5471  2017-10-14 11:07  AforgeCameraOne\AforgeCameraOne\AforgeCameraOne.csproj
     文件         279  2017-10-17 08:41  AforgeCameraOne\AforgeCameraOne\App.config
     目录           0  2017-10-13 22:14  AforgeCameraOne\AforgeCameraOne\bin\
     目录           0  2017-10-17 09:40  AforgeCameraOne\AforgeCameraOne\bin\Debug\
     文件       44544  2013-07-15 23:04  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.Controls.dll
     文件       17920  2013-07-15 23:04  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.dll
     文件      262656  2013-07-15 23:04  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.Imaging.dll
     文件       68096  2013-07-15 23:04  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.Math.dll
     文件      270650  2013-07-15 23:04  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.Math.xml
     文件       61440  2013-07-15 23:04  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.Video.DirectShow.dll
     文件       20992  2013-07-15 23:04  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.Video.dll
     文件       61952  2013-07-15 23:07  AforgeCameraOne\AforgeCameraOne\bin\Debug\AForge.Video.FFMPEG.dll
     文件       18432  2017-10-17 09:40  AforgeCameraOne\AforgeCameraOne\bin\Debug\AforgeCameraOne.exe
     文件         279  2017-10-17 08:41  AforgeCameraOne\AforgeCameraOne\bin\Debug\AforgeCameraOne.exe.config
     文件       32256  2017-10-17 09:40  AforgeCameraOne\AforgeCameraOne\bin\Debug\AforgeCameraOne.pdb
     文件       23168  2017-10-17 09:40  AforgeCameraOne\AforgeCameraOne\bin\Debug\AforgeCameraOne.vshost.exe
     文件         279  2017-10-17 08:41  AforgeCameraOne\AforgeCameraOne\bin\Debug\AforgeCameraOne.vshost.exe.config
     文件         490  2015-06-04 12:48  AforgeCameraOne\AforgeCameraOne\bin\Debug\AforgeCameraOne.vshost.exe.manifest
     文件    13698048  2013-01-29 15:58  AforgeCameraOne\AforgeCameraOne\bin\Debug\avcodec-53.dll
     文件      350208  2013-01-29 15:58  AforgeCameraOne\AforgeCameraOne\bin\Debug\avdevice-53.dll
     文件      924672  2013-01-29 15:58  AforgeCameraOne\AforgeCameraOne\bin\Debug\avfilter-2.dll
     文件     2523136  2013-01-29 15:58  AforgeCameraOne\AforgeCameraOne\bin\Debug\avformat-53.dll
     文件      139776  2013-01-29 15:58  AforgeCameraOne\AforgeCameraOne\bin\Debug\avutil-51.dll
     目录           0  2017-10-17 09:36  AforgeCameraOne\AforgeCameraOne\bin\Debug\MyVideo\
     目录           0  2017-10-17 09:40  AforgeCameraOne\AforgeCameraOne\bin\Debug\PersonImg\
     文件      161280  2013-01-29 15:58  AforgeCameraOne\AforgeCameraOne\bin\Debug\postproc-52.dll
     文件       35840  2013-01-29 15:58  AforgeCameraOne\AforgeCameraOne\bin\Debug\swresample-0.dll
............此处省略32个文件信息

评论

共有 条评论