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

资源简介

本程序是使用Aforge类库调用摄像头的demo

资源截图

代码片段和文件信息

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

namespace CameraDemo
{
    public partial class aforgeForm : Form
    {
        #region var
        private FilterInfoCollection cameraDevices;
        private VideoCaptureDevice cameraDevice;
        private const string noCameraDevice = “没有找到摄像头设备“;
        private bool isSingleCamera = false;
        #endregion
        public aforgeForm()
        {
            InitializeComponent();
        }

        private void aforgeForm_Load(object sender EventArgs e)
        {
            printCameraList();
            loadCameraList();
            if (isSingleCamera)
                preview();
        }

        private void preview()
        {
            if (null != cameraDevice)
            {
                preview_player.SignalToStop();
                preview_player.WaitForStop();
            }
            cameraDevice = new VideoCaptureDevice(cameraDevices[cameraId_cob.SelectedIndex].MonikerString);
            cameraDevice.DesiredframeSize = new Size(320 240);
            cameraDevice.DesiredframeRate = 1;
            preview_player.VideoSource = cameraDevice;
            preview_player.Start();
        }

        private void loadCameraList()
        {
            if (cameraDevices.Count == 0)
            {
                capture_btn.Enabled = false;
                cameraId_cob.Enabled = false;
                preview_btn.Enabled = false;
                guide_lab.Text = noCameraDevice;
                cameraDevices = null;

            }else if(cameraDevices.Count == 1)
            {
                isSingleCamera = true;
                preview_btn.Enabled = false;
                guide_lab.Visible = false;
            }
            foreach (FilterInfo cameraDevice in cameraDevices)
            {
                cameraId_cob.Items.Add(cameraDevice.Name);
                cameraId_cob.SelectedIndex = 0;
            }

        }

        private void printCameraList()
        {
                cameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
        }

        private void preview_btn_Click(object sender EventArgs e)
        {
            preview();
        }

        private void capture_btn_Click(object sender EventArgs e)
        {
            takePhoto();
        }

        private void takePhoto()
        {
            if (cameraDevice == null)
                return;
            Bitmap bitmap = preview_player.GetCurrentVideoframe();
            string fullPath = Application.StartupPath + “\\“;
            if (!Directory.Exists(fullPath))
                Directory.CreateDirectory(fullPath);
            string img = fullPath + “Aforge.bmp“;
            bitm

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

     文件        997  2016-12-09 09:20  CameraDemo.sln

    I.A....      5917  2016-12-09 17:30  AforgeDemo\AforgeDemo.csproj

    I.A....       479  2016-12-09 17:30  AforgeDemo\AforgeDemo.csproj.user

    I.A....      3326  2016-12-09 17:30  AforgeDemo\AforgeForm.cs

    I.A....      7055  2016-12-09 17:30  AforgeDemo\AforgeForm.Designer.cs

    I.A....      5817  2016-12-09 17:30  AforgeDemo\AforgeForm.resx

    I.A....       189  2016-12-09 17:30  AforgeDemo\App.config

    I.A....     44544  2016-12-09 17:30  AforgeDemo\lib\AForge.Controls.dll

    I.A....     17920  2016-12-09 17:30  AforgeDemo\lib\AForge.dll

    I.A....    262656  2016-12-09 17:30  AforgeDemo\lib\AForge.Imaging.dll

    I.A....     61440  2016-12-09 17:30  AforgeDemo\lib\AForge.Video.DirectShow.dll

    I.A....     20992  2016-12-09 17:30  AforgeDemo\lib\AForge.Video.dll

    I.A....       527  2016-12-09 17:30  AforgeDemo\Program.cs

    I.A....      1338  2016-12-09 17:30  AforgeDemo\Properties\AssemblyInfo.cs

    I.A....      2860  2016-12-09 17:30  AforgeDemo\Properties\Resources.Designer.cs

    I.A....      5612  2016-12-09 17:30  AforgeDemo\Properties\Resources.resx

    I.A....      1110  2016-12-09 17:30  AforgeDemo\Properties\Settings.Designer.cs

    I.A....       249  2016-12-09 17:30  AforgeDemo\Properties\Settings.settings

     目录          0  2016-12-09 17:30  AforgeDemo\lib

     目录          0  2016-12-09 17:30  AforgeDemo\Properties

     目录          0  2016-12-14 11:14  AforgeDemo

----------- ---------  ---------- -----  ----

               443028                    21


评论

共有 条评论