AForge官网地址:http://www.aforgenet.com/framework/

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;
using AForge.Video.DirectShow;
using AForge.Video; namespace AForgeDemo
{
public partial class Form1 : Form
{
private bool DeviceExist = false;
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource = null; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
getCamList();
} private void getCamList()
{
try
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
cbDev.Items.Clear();
if (videoDevices.Count == 0)
throw new ApplicationException();
DeviceExist = true;
foreach (FilterInfo device in videoDevices)
{
cbDev.Items.Add(device.Name);
}
cbDev.SelectedIndex = 0;
}
catch (ApplicationException)
{
DeviceExist = false;
cbDev.Items.Add("无设备");
}
} private void CloseVideoSource()
{
if (!(videoSource == null))
if (videoSource.IsRunning)
{
videoSource.SignalToStop();
videoSource = null;
}
} private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap img = (Bitmap)eventArgs.Frame.Clone();
picVideo.Image = img;
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
CloseVideoSource();
} private void btnOpen_Click(object sender, EventArgs e)
{
if (DeviceExist)
{
videoSource = new VideoCaptureDevice(videoDevices[cbDev.SelectedIndex].MonikerString);
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
CloseVideoSource();
videoSource.DesiredFrameSize = new Size(picVideo.Width, picVideo.Height);
videoSource.Start();
lbinfo.Text = "设备运行...";
}
else
{
lbinfo.Text = "没有选择设备";
}
} private void btnStop_Click(object sender, EventArgs e)
{
if (videoSource.IsRunning)
{
CloseVideoSource();
lbinfo.Text = "设备停止";
}
} }
}

效果图:

附件下载

C# 使用AForge调用摄像头的更多相关文章

  1. AForge调用摄像头拍照时设置分辨率

    简单记录下AForge2.2.5.0版本调用摄像头拍照时设置分辨率的方法. FilterInfo info = _videoDevices[0];//获取第一个摄像头 _cameraDevice = ...

  2. C#使用Aforge调用摄像头拍照

    一. 新建一个Winform项目 二.使用Nuget添加引用 安装下图中红色框住的两个程序包 安装完后发现安装了如下图的程序包,这是因为上述两个程序包存在对其它程序包的依赖. 三.编写程序 1. 窗体 ...

  3. Emgucv(一)Aforge切换摄像头并调用摄像头属性

    一.新建一个Windows窗体应用程序,在Form1窗体上添加一个PictureBox控件.一个ComboBox控件,命名为PictureBox1.cbCapture,还有两个Button控件,Tex ...

  4. C# - VS2019调用AForge库实现调用摄像头拍照功能

    前言 作为一名资深Delphi7程序员,想要实现摄像头扫描一维码/二维码功能,发现所有免费的第三方库都没有简便的实现办法,通用的OpenCV或者ZXing库基本上只支持XE以上的版本,而且一维码的识别 ...

  5. C#调用摄像头(AForge)实现扫描条码解析(Zxing)功能

    网上找了很多代码,都比较零散,以下代码纯自己手写,经过测试.下面有链接,下载后可以直接使用. 介绍: 自动识别:点击Start按钮会调用PC摄像头,代码内置Timer,会每100毫秒识别一下当前摄像头 ...

  6. 【C#】#100 调用摄像头

    需求:由于项目需要获得用户的头像,所以需要用C#调用摄像头获取头像. 下面写一个调用摄像头的方法 案例:调用摄像头的一个DEMO[效果图] 使用的类库:AForge.dll   [Demo下载,Dem ...

  7. C# winfrom调用摄像头扫描二维码(完整版)

    前段时间看到一篇博客,是这个功能的,参考了那篇博客写了这个功能玩一玩,没有做商业用途.发现他的代码给的有些描述不清晰的,我就自己整理一下发出来记录一下. 参考博客链接:https://www.cnbl ...

  8. unity调用摄像头的方法

    http://blog.csdn.net/cocoa_china/article/details/10527995 using UnityEngine; using System.Collection ...

  9. java javacv调用摄像头并拍照

    调用摄像头并拍张照片,我一开始用的java的jmf媒体框架,但这个有很多的局限性不好使并且很有麻烦,兜了一圈发现javacv东西,研究之后这东西简单,方便:废话不多说了来重点. javacv官网:点击 ...

  10. Android入门(十六)调用摄像头相册

    原文链接:http://www.orlion.ga/665/ 一.调用摄像头 创建一个项目ChoosePicDemo,修改activity_main.xml: <LinearLayout xml ...

随机推荐

  1. Git识别文件权限修改

    刚打开IDE,工作区的代码状态全部变成修改未提交的状态了?这是这么回事?这是因为Git忽略文件权限或者拥有者改变导致的git状态变化.默认Git会记录文件的权限信息,如果文件的权限信息被修改,在Git ...

  2. tensorflow中交叉熵损失函数详解

    1 前言 tensorflow中定义了3个交叉熵损失函数: softmax_cross_entropy_with_logits(logits, labels) softmax_cross_entrop ...

  3. 使用docker stack方式部署web集群

    如何部署swarm集群,请参考: https://blog.csdn.net/IndexMan/article/details/102713777 创建文件夹 mkdir -p /opt/docker ...

  4. Java集合框架学习(三) TreeSet详解

    TreeSet介绍 1.TreeSet是SortedSet接口的唯一实现类,TreeSet可以确保集合元素处于排序状态. 2.向TreeSet中加入的应该是同一个类的对象. 3.TreeSet判断两个 ...

  5. 突破Windows的极限

    偶然碰到这类技术博客,甚感欣慰,但奈何技术水平达不到,很多都难以理解,故记录在此,用作日后学习. 国内有类似的中文翻译,比如:突破Windows极限:物理内存 但是外文链接已经失效,看不到原汁原味的英 ...

  6. RHEL8重置root用户密码步骤

    要先确定是否为RHEL 8系统. [root@zhangsan ~]# cat /etc/redhat-release Red Hat Enterprise Linux release 8.0 (Oo ...

  7. mp4v2开发笔记(一): mp4v2库介绍,mp4v2在ubuntu上交叉编译移植到海思Hi35xx平台

    前言   在海思上需要将h264码流封装成mp4可使用mp4v2库.   其他相关   <Qt开发笔记之编码x264码流并封装mp4(四):mp4v2库的介绍和windows平台编译>   ...

  8. 【Filament】Filament环境搭建

    1 前言 ​ Filament 是一个实时物理渲染引擎,用于 Android.iOS.Linux.macOS.Windows 和 WebGL 平台.该引擎旨在提供高效.实时的图形渲染,并被设计为在 A ...

  9. Linux_Centos_yum报错总结

    ​ 此篇适用于yum报错[尝试其他镜像]并且[curl 外网]不通的情况,此时一般考虑是网络的问题 一,出现的报错信息: 此时测试curl / ping www.baidu.com会发现无法连通 二, ...

  10. SpringCloud Nacos

    1.Nacos简介 SpringCloud Alibaba 由来: 因为原先Spring Cloud 的许多组件都是对Netflix 公司的各种框架进行封装, 然后因为Netflix公司对后续更新的各 ...