C#调用本地摄像头-AForge库简单使用
介绍
AForge百度词条:
https://baike.baidu.com/item/AForge.NET/114415?fr=aladdin
用途
调用笔记本电脑自带的相机
示例
源码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Controls;
using AForge.Video;
using AForge.Imaging;
using AForge.Math;
using AForge.Video.DirectShow;
using System.Drawing.Imaging;
namespace LocalCamera
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
FilterInfoCollection videoDevices;
VideoCaptureDevice videoSource;
public int selectedDeviceIndex = 0;
private void OpenCamera_Click(object sender, EventArgs e)
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
selectedDeviceIndex = 0;
videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。
videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
videoDev.VideoSource = videoSource;
// set NewFrame event handler
videoDev.Start();
}
private void Photo_Click(object sender, EventArgs e)
{
{
if (videoSource == null)
return;
else
{
Bitmap bitmap = videoDev.GetCurrentVideoFrame();
Picture1.Image = bitmap;
//string fileName = "54250.jpg";//DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ff") + ".jpg";
//bitmap.Save(@"D:\" + fileName, ImageFormat.Jpeg);
//bitmap.Dispose();
}
}
}
private void CloseCamera_Click(object sender, EventArgs e)
{
videoDev.Stop();
}
}
}
运行结果
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Controls;
using AForge.Video;
using AForge.Imaging;
using AForge.Math;
using AForge.Video.DirectShow;
using System.Drawing.Imaging;
namespace LocalCamera
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
FilterInfoCollection videoDevices;
VideoCaptureDevice videoSource;
public int selectedDeviceIndex = 0;
private void OpenCamera_Click(object sender, EventArgs e)
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
selectedDeviceIndex = 0;
videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。
videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
videoDev.VideoSource = videoSource;
// set NewFrame event handler
videoDev.Start();
}
private void Photo_Click(object sender, EventArgs e)
{
{
if (videoSource == null)
return;
else
{
Bitmap bitmap = videoDev.GetCurrentVideoFrame();
Picture1.Image = bitmap;
//string fileName = "54250.jpg";//DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ff") + ".jpg";
//bitmap.Save(@"D:\" + fileName, ImageFormat.Jpeg);
//bitmap.Dispose();
}
}
}
private void CloseCamera_Click(object sender, EventArgs e)
{
videoDev.Stop();
}
}
}

项目下载
链接:https://pan.baidu.com/s/18y9MvF7ku_mKLt-3ZJg5CA
提取码:pp62
参考博客
https://blog.csdn.net/FL1623863129/article/details/78143211
C#调用本地摄像头-AForge库简单使用的更多相关文章
- H5混合开发二维码扫描以及调用本地摄像头
今天主管给了我个需求,说要用混合开发,用H5调用本地摄像头进行扫描二维码,我之前有做过原生安卓的二维码扫一扫,主要是通过调用zxing插件进行操作的,其中还弄了个闪光灯.但是纯H5的没接触过,心里没底 ...
- 调用本地摄像头拍照(H5和画布)
关于H5 和 画布 调用本地摄像头拍照功能的实现 1.代码的实现(html部分) <input type="button" title="开启摄像头" v ...
- 利用html5调用本地摄像头拍照上传图片[转]
利用html5调用本地摄像头拍照上传图片 html5概念啥的就不废话了,不知道的 百度, 谷歌一堆..今天学了学html5中的Canvas结合新增的<video>标签来获取本地摄像头, ...
- HTML5调用本地摄像头画面,拍照,上传服务器
实现功能和适用业务 采集本地摄像头获取摄像头画面,拍照保存,上传服务器: 前端上传图片处理,展示,缩小,裁剪,上传服务器 实现步骤 调取本地摄像头(getUserMedia)/上传图片,将图片/视频显 ...
- 调用本地摄像头并通过canvas拍照
首先我们需要新建一个video标签,并且放到html里边 var video = document.createElement("video"); video.autoplay=& ...
- 前端调用本地摄像头实现拍照(vue)
由于调用摄像头有使用权限,只能在本地运行,线上需用https域名才可以使用. <template> <div class="camera_outer"> & ...
- 利用html5调用本地摄像头拍照上传图片
这个是前台HTML的代码. <div id="contentHolder"> <video id="video" width="32 ...
- H5实现调用本地摄像头实现实时视频以及拍照功能
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- H5调用本地摄像头
<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"& ...
随机推荐
- BZOJ 4141 [Thu Summer Camp 2013]魔塔
权限题qwq 以下设值域大小为\(m\) 先考虑枚举攻击力,因为首先攻击力决定每个怪物的攻击次数,然后对于每个怪物,攻击次数为\(\lceil\frac{hp_i}{ATK-def_i}\rceil\ ...
- apache的rewrite机制
当我们使用thinkphp的时候,比如说我们访问一个Test控制器的test方法,http://localhost/index.php/Test/test/1.html,那个这个1是用get方式传递的 ...
- pyhton接口自动化测试-requests.post()
一.方法定义 二.post方法简单使用 1.带数据的post 2.带header的post 3.带json的post 4.带参数的post 5.普通文件上传 6.定制化文件上传 7.多文件上传 一.方 ...
- 再谈变分自编码器VAE:从贝叶斯观点出发
链接:https://kexue.fm/archives/5343
- Django学习系列3:创建仓库
在创建仓库之前,在项目superlists中新建一个Python文件,命名为functional_tests.py,里面的内容如下: # File: functional_test.py # Auth ...
- #1055 ... sql_mode=only_full_group_by
sql_mode=only_full_group_by 版权声明:本文为参考多篇博主文章,略作测试修改. 参考文章: 猿医生 的<5分钟学会MySQL-this is incompatible ...
- ThinkPHP中的SQL结果分析
ThinkPHP中的SQL结果分析 在进行结果判断时需要注意. 一.查询SQL: 可能出现的情况:1.查询成功,返回正常数据.2.查询成功,但是没有数据,返回NULL.3.查询错误,写错关键字.结果: ...
- ARM汇编 汇编文件后缀.s与.S
有两套汇编的语法: ARM公司的标准ARM汇编语言和GNU对ARM支持的GNU ARM汇编. ARM标准汇编语言即ARM公司的开发工具ADS里用的汇编语言: GNU汇编即在Linux下用GCC编译的汇 ...
- solairs11与solairs10 ftp服务的区别
Migration from Solaris WU-FTPD to ProFTPD Introduction ------------ This document provides an overvi ...
- 曝郭盛华公司30万美元收购Acn.ai域名,揭秘人工智能布局下的巨头们
据域名投资人曝料,郭盛华公司已经提前拿下.ai短域名 Acn.ai,目前域名已经设置跳转到东联科技的官网.都说域名越短越值钱,而且搜索引擎都喜欢更短的域名,例如京东更换的域名“jd.com”交易价格约 ...