资源简介
本程序是使用Aforge类库调用摄像头的demo
代码片段和文件信息
using AForge.Video.DirectShow;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CameraDemo
{
public partial class aforgeForm : Form
{
#region var
private FilterInfoCollection cameraDevices;
private VideoCaptureDevice cameraDevice;
private const string noCameraDevice = “没有找到摄像头设备“;
private bool isSingleCamera = false;
#endregion
public aforgeForm()
{
InitializeComponent();
}
private void aforgeForm_Load(object sender EventArgs e)
{
printCameraList();
loadCameraList();
if (isSingleCamera)
preview();
}
private void preview()
{
if (null != cameraDevice)
{
preview_player.SignalToStop();
preview_player.WaitForStop();
}
cameraDevice = new VideoCaptureDevice(cameraDevices[cameraId_cob.SelectedIndex].MonikerString);
cameraDevice.DesiredframeSize = new Size(320 240);
cameraDevice.DesiredframeRate = 1;
preview_player.VideoSource = cameraDevice;
preview_player.Start();
}
private void loadCameraList()
{
if (cameraDevices.Count == 0)
{
capture_btn.Enabled = false;
cameraId_cob.Enabled = false;
preview_btn.Enabled = false;
guide_lab.Text = noCameraDevice;
cameraDevices = null;
}else if(cameraDevices.Count == 1)
{
isSingleCamera = true;
preview_btn.Enabled = false;
guide_lab.Visible = false;
}
foreach (FilterInfo cameraDevice in cameraDevices)
{
cameraId_cob.Items.Add(cameraDevice.Name);
cameraId_cob.SelectedIndex = 0;
}
}
private void printCameraList()
{
cameraDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
}
private void preview_btn_Click(object sender EventArgs e)
{
preview();
}
private void capture_btn_Click(object sender EventArgs e)
{
takePhoto();
}
private void takePhoto()
{
if (cameraDevice == null)
return;
Bitmap bitmap = preview_player.GetCurrentVideoframe();
string fullPath = Application.StartupPath + “\\“;
if (!Directory.Exists(fullPath))
Directory.CreateDirectory(fullPath);
string img = fullPath + “Aforge.bmp“;
bitm
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 997 2016-12-09 09:20 CameraDemo.sln
I.A.... 5917 2016-12-09 17:30 AforgeDemo\AforgeDemo.csproj
I.A.... 479 2016-12-09 17:30 AforgeDemo\AforgeDemo.csproj.user
I.A.... 3326 2016-12-09 17:30 AforgeDemo\AforgeForm.cs
I.A.... 7055 2016-12-09 17:30 AforgeDemo\AforgeForm.Designer.cs
I.A.... 5817 2016-12-09 17:30 AforgeDemo\AforgeForm.resx
I.A.... 189 2016-12-09 17:30 AforgeDemo\App.config
I.A.... 44544 2016-12-09 17:30 AforgeDemo\lib\AForge.Controls.dll
I.A.... 17920 2016-12-09 17:30 AforgeDemo\lib\AForge.dll
I.A.... 262656 2016-12-09 17:30 AforgeDemo\lib\AForge.Imaging.dll
I.A.... 61440 2016-12-09 17:30 AforgeDemo\lib\AForge.Video.DirectShow.dll
I.A.... 20992 2016-12-09 17:30 AforgeDemo\lib\AForge.Video.dll
I.A.... 527 2016-12-09 17:30 AforgeDemo\Program.cs
I.A.... 1338 2016-12-09 17:30 AforgeDemo\Properties\AssemblyInfo.cs
I.A.... 2860 2016-12-09 17:30 AforgeDemo\Properties\Resources.Designer.cs
I.A.... 5612 2016-12-09 17:30 AforgeDemo\Properties\Resources.resx
I.A.... 1110 2016-12-09 17:30 AforgeDemo\Properties\Settings.Designer.cs
I.A.... 249 2016-12-09 17:30 AforgeDemo\Properties\Settings.settings
目录 0 2016-12-09 17:30 AforgeDemo\lib
目录 0 2016-12-09 17:30 AforgeDemo\Properties
目录 0 2016-12-14 11:14 AforgeDemo
----------- --------- ---------- ----- ----
443028 21
相关资源
- C# 调用win32 api函数-user32.dll详细说明
- C# 调用BarTender打印条码DEMO
- 大型比赛竞赛抽签系统 可打印 c# vs
- C#编写的Gerber查看器
- lua C# .Net4.0 vs2010 LuaInterface
- C#十六进制编辑器
- 明华URF-35H读卡器 C#读写源码 为大家
- C#文件流读取CSV文件
- c#读写PDF文件sql
- C# winform Socket大文件传输
- c#车牌识别系统附30张测试图片
- 《C#面向对象程序设计》源代码(CS)
- 金旭亮《C#面向对象程序设计》教案
- 试题库管理系统毕业论文(C#)源程序
- 学校网站原代码(C#.NET)
- C#-数据库操作技术-员工管理系统
- c#web开发入门经典
- C#与Matlab混合编程的几种方式
- c# 开发与 mysql数据库实现的增删改查
- C#异步操作 异步查询数据库 异步处理
- Basler相机通过IO触发源码
- [源代码] 《领域驱动设计 (C# 2008 实
- 松下PLC与C#通讯串口调试入门教程.z
- USB 继电器控制器 LCUS-1 保证能用 c#
- C# AES加密解密小工具
- C#圆形按钮,非常漂亮动态~~
- [精]C#仿QQ右下角弹出提示框()
- C#进程间通信-共享内存代码
- 有史以来最简单的三层(C#)
- vb调用c#编写的串口DLL文件(vb源码
评论
共有 条评论