C#利用摄像头拍照功能实现
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics; using AForge;
using AForge.Video;
using AForge.Controls;
using AForge.Video.DirectShow;
using AForge.Video.FFMPEG;
using AForge.Imaging;
using AForge.Imaging.Filters;
using System.IO;
namespace Camera
{
public partial class Form1 : Form
{
private FilterInfoCollection videoDevices;
private VideoCaptureDevice videoSource;
private bool stopREC = true;
private bool createNewFile = true; private string videoFileFullPath = string.Empty; //视频文件全路径
private string imageFileFullPath = string.Empty; //图像文件全路径
private string videoPath = @"E:\video\"; //视频文件路径 private string videoFileName = string.Empty; //视频文件名
private string imageFileName = string.Empty; //图像文件名
private string drawDate = string.Empty;
private VideoFileWriter videoWriter = null; public delegate void MyInvoke(); //定义一个委托方法 string g_s_AutoSavePath = AppDomain.CurrentDomain.BaseDirectory + "Capture\\";
object objLock = new object(); //定义一个对象的锁
int frameRate = 20; //默认帧率
private Stopwatch stopWatch = null;
IVideoSource iVideoSource = null;
private int flag = 0;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
try
{
// 枚举所有视频输入设备
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); if (videoDevices.Count == 0)
throw new ApplicationException(); foreach (FilterInfo device in videoDevices)
{
tscbxCameras.Items.Add(device.Name);
} tscbxCameras.SelectedIndex = 0;
}
catch (ApplicationException)
{
tscbxCameras.Items.Add("No local capture devices");
videoDevices = null;
}
} private void toolStripButton1_Click(object sender, EventArgs e)
{
CameraConn();
} private void CameraConn()
{
videoSource = new VideoCaptureDevice(videoDevices[tscbxCameras.SelectedIndex].MonikerString);
videoSource.DesiredFrameSize = new Size(320, 240);
videoSource.DesiredFrameRate = 1; videoPlayer.VideoSource = videoSource;
videoPlayer.Start();
} private void toolStripButton2_Click(object sender, EventArgs e)
{
videoPlayer.SignalToStop();
videoPlayer.WaitForStop();
} private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
toolStripButton2_Click(null, null);
} private void button2_Click(object sender, EventArgs e)
{
try
{
flag = 0;
videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame); }
catch (Exception ex)
{
MessageBox.Show("捕获图像失败!" + ex.Message, "提示");
}
}
private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
if (flag == 0)
{
string img = "E://img//" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg";
bitmap.Save(img);
MessageBox.Show("ok");
flag = 1;
}
} }
}
具体:1.调用各个dll文件
2.AForge.Controls生成自身控件videoPlayer
C#利用摄像头拍照功能实现的更多相关文章
- winform摄像头拍照 C#利用摄像头拍照
这是我的第一篇博文,决定以后每个程序都要记录下来,方便以后查阅! 本人小菜一名,本程序也是查阅了网上各位前辈的博客和百度知道所整理出来的一个小程序. 第一次写有点不知道从何写起,先贴一张程序图吧. 程 ...
- C# - VS2019调用AForge库实现调用摄像头拍照功能
前言 作为一名资深Delphi7程序员,想要实现摄像头扫描一维码/二维码功能,发现所有免费的第三方库都没有简便的实现办法,通用的OpenCV或者ZXing库基本上只支持XE以上的版本,而且一维码的识别 ...
- h5获取摄像头拍照功能
完整代码展示 <!DOCTYPE html> <head> <title>HTML5 GetUserMedia Demo</title> <met ...
- 谷歌使用navigator.mediaDevices.getUserMedia 调用摄像头拍照功能,不兼容IE
<template> <div> <!--canvas截取流--> <canvas ref="canvas" ...
- 调用本地摄像头拍照(H5和画布)
关于H5 和 画布 调用本地摄像头拍照功能的实现 1.代码的实现(html部分) <input type="button" title="开启摄像头" v ...
- VS2010开发MFC ActiveX,摄像头拍照上传Webservice(2)
继续记录,第二步开发摄像头拍照功能. 使用vfw.h开发摄像头拍照功能,关于vfw网上有很多文章,很多代码可以参考 参考:http://blog.163.com/huangqiao_8/blog/st ...
- VS2010开发MFC ActiveX,摄像头拍照上传Webservice(1)
最近工作项目,BS中需要用到摄像头拍照,需要存储本地,同时上传到服务器,尝试使用vc++做ActiveX来实现. 完全没有使用过vc,上网搜索各种知识,初步完成.在这里记录下有帮助的资料. 第一步:编 ...
- C#操作摄像头 实现拍照功能
从正式工作以来一直做的都是基于B/S的Web开发,已经很长时间不研究C/S的东西了,但是受朋友的委托,帮他做一下拍照的这么个小功能.其实类似的代码网上有很多,但是真的能够拿来运行的估计也没几个.本来是 ...
- 利用html5调用本地摄像头拍照上传图片[转]
利用html5调用本地摄像头拍照上传图片 html5概念啥的就不废话了,不知道的 百度, 谷歌一堆..今天学了学html5中的Canvas结合新增的<video>标签来获取本地摄像头, ...
随机推荐
- ElasticSearch 5.0.1 java API操作
今天来说下使用ES 5.0.1的API来进行编码. 开始之前,简单说下5.0.1跟之前的几个变化.之前的ES自身是不支持delete-by-query的,也就是通过查询来删除,可以达到批量的效果,是因 ...
- jQuery基础1
jQuery是轻量级的JavaScript库,jQuery 库位于一个 JavaScript 文件中,其中包含了所有的 jQuery 函数.更少的代码做更多的事. jQuery 可以选取某些元素并执行 ...
- Android 常用布局视图
常用包 http://square.github.io/ EventBus Scroller 滚动 拖拽 # android.support.design.widget.CollapsingToolb ...
- js实现图片的大小自适应效果
需求是传过来一个图片,根据外层div的大小自动进行缩放效果. function ShowSecondImg(v) { var rate, newX, newY,newW, newH = 0; //表示 ...
- 原生js通过prottype写的一个简单拖拽
<!DOCTYPE html> <head> <meta charset="utf-8"/> <title></title&g ...
- spring+mybatis+springmvc的配置
1.web.xml的配置 <?xml version="1.0" encoding="UTF-8"?><web-app version=&qu ...
- TextMate2 最新版下载及源码编译过程
TextMate2 已经开源,我刚编译成功,如果有需要的同学可以点击下面百度网盘的链接下载.我系统版本是:Mac OS X 10.8.4. TextMate version 2.0-alpha.946 ...
- asp.net MVC之 自定义过滤器(Filter) - shuaixf
一.系统过滤器使用说明 1.OutputCache过滤器 OutputCache过滤器用于缓存你查询结果,这样可以提高用户体验,也可以减少查询次数.它有以下属性: Duration :缓存的时间, 以 ...
- 【图像处理】【SEED-VPM】1.注意点
1. 新装系统要启动NFX 每次虚拟机复位要执行以下命令 /usr/sbin/exportfs -av /sbin/service nfs restart —————————————————————— ...
- Dependency Scope
Dependency Scope <dependency>中还引入了<scope>,它主要管理依赖的部署.目前<scope>可以使用5个值: * compile,缺 ...