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. mysql执行大量sql语句

    今天需要通过csv上传大量数据到数据库 直接逐行执行insert效率极其低下 后面通过拼接insert,稍微提高了些许效率,但依然不满足 最后发现,把这些插入放入同一个事务里面可以大大提高效率 beg ...

  2. 获取sql server数据库表结构

    if exists (select 1 from sysobjects where name = 'sysproperties'and xtype = 'V')begin    DROP VIEW s ...

  3. JS根据登录的城市不同调用不同的内容

    这个思路就是通过js获取访问客户的IP地址,根据IP接口判断IP的所属城市 1.先引入ip接口的js文件,网上有很多,这里用的是新浪的(感谢新浪) <script type="text ...

  4. C#WebForm内置对象

    内置对象: Response对象:响应请求Response.Write("<script>alert('添加成功!')</script>");Respons ...

  5. Windows Store App 网络通信 HttpWebRequest

    如果希望更好地控制HTTP请求,可以使用System.Net类库中的HttpWebRequest类,该类对HTTP协议进行了完整的封装,并且提供了很多对HTTP协议中的 Header.Content和 ...

  6. JavaScript 面向对象(一) —— 基础篇

    学好JS的面向对象,能很大程度上提高代码的重用率,像jQuery,easyui等,这篇博客主要从细节上一步步讲JS中如何有效地创建对象,也可以看到常见的创建对象的方式,最后也会附上一些JS面向对象的案 ...

  7. Struts2 Result 类型和对应的用法详解

  8. java 从数据删除指定值

    public class ArrayRemoveValue { public static void main(String[] args) { Integer[] _IntArray = new I ...

  9. 修改Linux默认启动级别或模式的方法

    冲动的惩罚: 海阔天空: 在linux系统的7种启动级别,默认为X-Window,类似于Windows的窗口模式. 如何修改或变更linux的默认启动级别或模式呢? 以root身份进入Linux,修改 ...

  10. 面试复习(C++)之堆排序

    #include <iostream> using namespace std; void Maxheap(int *a,int i,int heapSize)//最大数调整 { +;// ...