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"& ...
随机推荐
- python中魔法方法__str__与__repr__的区别
提出问题 当我们自定义一个类时,打印这个类对象或者在交互模式下直接输入这个类对象按回车,默认显示出来的信息好像用处不大.如下所示 In [1]: class People: ...: def __in ...
- Gym 101466(完整)
题目链接 :点击此处 ## Problem A 题意: 给你n个数,重定义两个数之间的加法不进位,求这些数中两个数相加的最大值和最小值. 题解: 字典树.我们首先将前i-1为放入字典树中,然后在查询第 ...
- [Vue] vuex-interview
1.你有使用过 vuex 的 module 吗?主要是在什么场景下使用? 把状态全部集中在状态树上,非常难以维护. 按模块分成多个 module,状态树延伸多个分支,模块的状态内聚,主枝干放全局共享状 ...
- sql server 函数详解(1)字符串函数
ASCII()函数 CHAR()函数 LEFT()函数 RIGHT()函数 LTRIM()函数 RTRIM()函数 STR()函数 字符串逆序的函数REVERSE() 计算字符串的长度函数LEN(st ...
- ElasticSearch实战系列四: ElasticSearch理论知识介绍
前言 在前几篇关于ElasticSearch的文章中,简单的讲了下有关ElasticSearch的一些使用,这篇文章讲一下有关 ElasticSearch的一些理论知识以及自己的一些见解. 虽然本人是 ...
- AIX系统的备份和恢复
1.AIX备份命令
- Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion' has value '1.8', but '1.7'
第一种方法:安装1.8之前安装了1.7,将1.7卸载就好了. 第二种方法:删掉Windows\System32下的java.exe, javaw.exe 就行了,但是安装的1.8的jdk会回到1.7的 ...
- Xunsearch入门
Xunsearch入门 简介: 开源免费.高性能.多功能.简单易用的专业全文检索技术方案. 1.Xunsearch安装: (1)官网(http://xunsearch.com)下载 wget http ...
- VxWorks引导启动过程
https://blog.csdn.net/phunxm/article/details/6979089
- controller 有两种写法,讨论一下两种写法的区别:
controller 有两种写法,讨论一下两种写法的区别: 写法 1: app.controller('myCtrl', function($scope, $location) { $scope.my ...