• 大小: 173KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-06-12
  • 语言: C#
  • 标签: Camera  AForge  摄像头  拍摄  

资源简介

在WIN7操作系统中, 资源管理器里面已经无法打开摄像头了, 这个小工具使用AForge类库实现C# 操作摄像头, 代码超级简捷 , 5行核心代码解决问题所有问题.

资源截图

代码片段和文件信息

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

using AForge;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Imaging;
using AForge.Imaging.Filters;

namespace Camera
{
    public partial class Form1 : Form
    {
        private FilterInfoCollection videoDevices;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            try
            {
                // 枚举所有视频输入设备
                videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);

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

                foreach (FilterInfo device in videoDevices)
                {
                    tscbxCameras.Items.Add(device.Name);
                }

                tscbxCameras.SelectedIndex = 0;
            }
            catch (ApplicationException)
            {
                tscbxCameras.Items.Add(“No local capture devices“);
                videoDevices = null;
            }
        }

        private void toolStripButton1_Click(object sender EventArgs e)
        {
            CameraConn();
        }

        private void CameraConn()
        {
            VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[tscbxCameras.SelectedIndex].MonikerString);
            videoSource.DesiredframeSize = new Size(320 240);
            videoSource.DesiredframeRate = 1;

            videPlayer.VideoSource = videoSource;
            videPlayer.Start();
        }

        private void toolStripButton2_Click(object sender EventArgs e)
        {
            videPlayer.SignalToStop();
            videPlayer.WaitForStop();
        }

        private void Form1_FormClosing(object sender FormClosingEventArgs e)
        {
            toolStripButton2_Click(null null);
        }


    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      14336  2008-10-12 13:34  Camera\Camera\bin\Debug\AForge.Controls.dll

     文件       9728  2008-11-16 11:45  Camera\Camera\bin\Debug\AForge.dll

     文件      97792  2008-11-18 10:46  Camera\Camera\bin\Debug\AForge.Imaging.dll

     文件      27136  2008-10-12 13:34  Camera\Camera\bin\Debug\AForge.Video.DirectShow.dll

     文件      13312  2008-10-12 13:34  Camera\Camera\bin\Debug\AForge.Video.dll

     文件      12800  2012-04-21 17:00  Camera\Camera\bin\Debug\Camera.exe

     文件      24064  2012-04-21 17:00  Camera\Camera\bin\Debug\Camera.pdb

     文件      11608  2012-04-21 17:03  Camera\Camera\bin\Debug\Camera.vshost.exe

     文件        490  2010-03-17 22:39  Camera\Camera\bin\Debug\Camera.vshost.exe.manifest

     文件       3994  2012-04-21 16:39  Camera\Camera\Camera.csproj

     文件       2174  2012-04-21 17:00  Camera\Camera\Form1.cs

     文件       5398  2012-04-21 16:56  Camera\Camera\Form1.Designer.cs

     文件       8399  2012-04-21 16:56  Camera\Camera\Form1.resx

     文件      14336  2008-10-12 13:34  Camera\Camera\Include\AForge.Controls.dll

     文件       9728  2008-11-16 11:45  Camera\Camera\Include\AForge.dll

     文件      97792  2008-11-18 10:46  Camera\Camera\Include\AForge.Imaging.dll

     文件      27136  2008-10-12 13:34  Camera\Camera\Include\AForge.Video.DirectShow.dll

     文件      13312  2008-10-12 13:34  Camera\Camera\Include\AForge.Video.dll

     文件        844  2012-04-21 17:03  Camera\Camera\obj\x86\Debug\Camera.csproj.FileListAbsolute.txt

     文件      12800  2012-04-21 17:00  Camera\Camera\obj\x86\Debug\Camera.exe

     文件       1978  2012-04-21 16:56  Camera\Camera\obj\x86\Debug\Camera.Form1.resources

     文件      24064  2012-04-21 17:00  Camera\Camera\obj\x86\Debug\Camera.pdb

     文件        180  2012-04-21 16:39  Camera\Camera\obj\x86\Debug\Camera.Properties.Resources.resources

     文件       9776  2012-04-21 16:23  Camera\Camera\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       5571  2012-04-21 17:00  Camera\Camera\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       3806  2012-04-21 16:56  Camera\Camera\obj\x86\Debug\ResGen.read.1.tlog

     文件        700  2012-04-21 16:56  Camera\Camera\obj\x86\Debug\ResGen.write.1.tlog

     文件      17492  2012-04-21 16:31  Camera\Camera\obj\x86\Debug\ResolveAssemblyReference.cache

     文件        467  2012-04-21 16:22  Camera\Camera\Program.cs

     文件       1362  2012-04-21 16:22  Camera\Camera\Properties\AssemblyInfo.cs

............此处省略19个文件信息

评论

共有 条评论