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#利用摄像头拍照功能实现的更多相关文章

  1. winform摄像头拍照 C#利用摄像头拍照

    这是我的第一篇博文,决定以后每个程序都要记录下来,方便以后查阅! 本人小菜一名,本程序也是查阅了网上各位前辈的博客和百度知道所整理出来的一个小程序. 第一次写有点不知道从何写起,先贴一张程序图吧. 程 ...

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

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

  3. h5获取摄像头拍照功能

    完整代码展示 <!DOCTYPE html> <head> <title>HTML5 GetUserMedia Demo</title> <met ...

  4. 谷歌使用navigator.mediaDevices.getUserMedia 调用摄像头拍照功能,不兼容IE

    <template>     <div>       <!--canvas截取流-->       <canvas ref="canvas" ...

  5. 调用本地摄像头拍照(H5和画布)

    关于H5 和 画布 调用本地摄像头拍照功能的实现 1.代码的实现(html部分) <input type="button" title="开启摄像头" v ...

  6. VS2010开发MFC ActiveX,摄像头拍照上传Webservice(2)

    继续记录,第二步开发摄像头拍照功能. 使用vfw.h开发摄像头拍照功能,关于vfw网上有很多文章,很多代码可以参考 参考:http://blog.163.com/huangqiao_8/blog/st ...

  7. VS2010开发MFC ActiveX,摄像头拍照上传Webservice(1)

    最近工作项目,BS中需要用到摄像头拍照,需要存储本地,同时上传到服务器,尝试使用vc++做ActiveX来实现. 完全没有使用过vc,上网搜索各种知识,初步完成.在这里记录下有帮助的资料. 第一步:编 ...

  8. C#操作摄像头 实现拍照功能

    从正式工作以来一直做的都是基于B/S的Web开发,已经很长时间不研究C/S的东西了,但是受朋友的委托,帮他做一下拍照的这么个小功能.其实类似的代码网上有很多,但是真的能够拿来运行的估计也没几个.本来是 ...

  9. 利用html5调用本地摄像头拍照上传图片[转]

    利用html5调用本地摄像头拍照上传图片   html5概念啥的就不废话了,不知道的 百度, 谷歌一堆..今天学了学html5中的Canvas结合新增的<video>标签来获取本地摄像头, ...

随机推荐

  1. swift_枚举 | 可为空类型 | 枚举关联值 | 枚举递归 | 树的概念

    ***************可为空的类型 var demo2 :we_demo = nil 上面这个代码串的语法是错的 为什么呢, 在Swift中,所有的类型定义出来的属性的默认值都不可以是nil ...

  2. Forward和Redirect的区别

    一:间接请求转发(Redirect) 二:直接请求转发(Forward) 用户向服务器发送了一次HTTP请求,该请求可能会经过多个信息资源处理以后才返回给用户,各个信息资源使用请求转发机制相互转发请求 ...

  3. 自己写的一个SqlHelper,感觉使用起来挺方便的

    自己写的一个SqlHelper,感觉使用起来挺方便的 using System; using System.Data; using System.Collections.Generic; using ...

  4. JAVA OO 第二章知识点

    一.JAVA的基础语法 1.关键字 ①关键字:关键字用于定义该门语言,且这些单词对编译器用特殊的含义,而且不能作为标识符. 2.标识符 标识符:在JAVA中我们备选的单词,包括:类名.方法名.字段.变 ...

  5. ArcMap Add-in插件开发中解决VS调试时断点不会命中的问题

    在VS2010中进行ArcMap Add-in插件开发(ArcEngine10.1,ArcGIS10.1),运行时为.NET4.0,在程序中设置了断点进行调试,但是运行后程序并不会在断点处停止,且原来 ...

  6. H5如何实现一行三列布局

    <!DOCTYPE html><html lang="en"><head>         <meta charset="UTF ...

  7. Android6.0获取权限

    照着<第一行代码>打代码,然并卵,感叹技术进步的神速.最后提醒一点:IT类的书籍一定要注意出版时间!出版时间!出版时间!重要的事情说三遍 问题出在android6.0的权限获取问题上,以前 ...

  8. deepin linux字体渲染(转)

    <?xml version='1.0'?> <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> <fontconfig> <ma ...

  9. js 判断IE浏览器,包含IE6/7/8/9

    //判断IE6-9的版本,num可取值为6/7/8/9//若不给参数num,仅判断浏览器是否为IE,不判断版本 var isIE = function (num) { if(arguments.len ...

  10. 对象列表转换为DataTable或DataTable转换为对象列表.

    /**********************************************************************************/ // 说明: 数据转换工具. ...