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. JavaScript查找数组是否存在指定元素

    利用JavaScript的函数有两种方式 1.jQuery jQuery.inArray( value, array [, fromIndex ] ) value 类型: Anything 要查找的值 ...

  2. Swift的 convenience && designated init

    http://www.th7.cn/Program/IOS/201603/789227.shtml 在 OC 中 init 方法是非常不安全的,没人能够保证 init 只被调用一次,也没有人保证在初始 ...

  3. Java—网络技术

    1  TCP Sockets基础 Sockets是一个编程抽象概念,它是网络上与另一个应用程序通信连接的句柄.Sockets编程将用户代码与TCP/IP协议堆栈的底层实现隔离开,允许用户灵活地实现自己 ...

  4. 权重和层叠规则决定了CSS样式优先级

    一.基本的优先级规则 比较同一级别的个数,数量多的优先级高,如果相同即比较下一级别的个数,至于各级别的优先级如下: important > 内联 > ID > 类 > 标签 | ...

  5. DynamicJson

    json字符串解析成Dynamic对象,开源地址http://dynamicjson.codeplex.com/,访问比较慢.使用方法摘录如下: Project Descriptiondynamic ...

  6. cacti结合nagios

    使用系统ubuntu12.0.45 监控软件,cacti 使用的是源码安装系统自带的版本过低需要添加插件 nagios采用的系统自带版本 安装nagios apt-get install nagios ...

  7. 学习docker

    虚拟机下Ubuntu环境 1.sudo apt-get update 2.sudo apt-get install docker.io 3.在daocloud(http://www.daocloud. ...

  8. yii2.0 Activeform表单部分组件使用方法

    文本框:textInput(); 密码框:passwordInput(); 单选框:radio(),radioList(); 复选框:checkbox(),checkboxList(); 下拉框:dr ...

  9. wxPython入门练习代码 三

    DoubleEventFrame.py: #!/usr/bin/env/ python import wx class DoubleEventFrame(wx.Frame): def __init__ ...

  10. Jquery的各种验证

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...