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"& ...
随机推荐
- H5头部meta标签的作用
<!DOCTYPE html> H5标准声明,使用 HTML5 doctype,不区分大小写 <head lang=”en”> 标准的 lang 属性写法 <meta ...
- char转int,int转char
char转int 1) '; if (Character.isDigit(ch)){ // 判断是否是数字 int num = Integer.parseInt(String.valueOf(ch)) ...
- java压缩文件中文名乱码问题
import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; 改为 import org.apache.tools.zip. ...
- urlencode编/解码
from urllib.parse import urlencode, quote, unquote # urlencode方法参数是字典 body = { "content": ...
- 关于导航自定义视图距离边界问题,点击状态栏TableView不能回滚到顶部问题
一: 默认Navigation的自定义customView,设置为 Left or Right BarButtonItem 的时候会 与屏幕边界有个15像素的距离. 导致自定义视图的上的子视图响应区域 ...
- 286-基于6U VPX 的mSATA高性能数据存储板
基于6U VPX 的mSATA高性能数据存储板 一.板卡概述 该产品系我司自主研发.基于标准6U VPX架构. 二.产品特性 最大存储容量8TB 读写方式RAID0 ,读写速 ...
- JDK12的安装搭建
JDK12的安装搭建 一.JDK下载 1.JDK官网下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk12-down ...
- Android 静态代码分析工具
简评: 作者在文中提到的三个静态代码分析工具不是互相替代的关系,各有各的侧重点,如果有需要完全可以同时使用. 静态代码分析是指无需运行被测代码,仅通过分析或检查源程序的语法.结构.过程.接口等来检查程 ...
- u-boot v2018.01 启动流程分析
https://blog.csdn.net/weixin_39655765/article/details/80058644#jump1 make smdkc100_defconfig 以被默 ...
- Java并发编程实战 第5章 构建基础模块
同步容器类 Vector和HashTable和Collections.synchronizedXXX 都是使用监视器模式实现的. 暂且不考虑性能问题,使用同步容器类要注意: 只能保证单个操作的同步. ...