c# 关于aforgenet获取本地摄像头
来源:互联网 发布:数字网络用语有哪些 编辑:程序博客网 时间:2024/05/17 21:38
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing.Imaging;using System.Text;using System.Windows;using System.Windows.Forms;using System.IO;using System.Windows.Media.Imaging;using AForge;using AForge.Controls;using AForge.Video;using AForge.Video.DirectShow;using Size = System.Drawing.Size;namespace OperateCamera{ public partial class Form1 : Form { private FilterInfoCollection videoDevices; private VideoCaptureDevice videoSource; 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 btnConnect_Click(object sender, EventArgs e) { CameraConn(); } //连接摄像头 private void CameraConn() { VideoCaptureDevice videoSource = new VideoCaptureDevice(videoDevices[tscbxCameras.SelectedIndex].MonikerString); videoSource.DesiredFrameSize = new System.Drawing.Size(320, 240); videoSource.DesiredFrameRate = 1; videoSourcePlayer.VideoSource = videoSource; videoSourcePlayer.Start(); } //关闭摄像头 private void btnClose_Click(object sender, EventArgs e) { videoSourcePlayer.SignalToStop(); videoSourcePlayer.WaitForStop(); } //主窗体关闭 private void Form1_FormClosing(object sender, FormClosingEventArgs e) { btnClose_Click(null, null); } //拍照 private void Photograph_Click(object sender, EventArgs e) { try { if (videoSourcePlayer.IsRunning) { BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( videoSourcePlayer.GetCurrentVideoFrame().GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); PngBitmapEncoder pE = new PngBitmapEncoder(); pE.Frames.Add(BitmapFrame.Create(bitmapSource)); string picName = GetImagePath() + "\\" + "xiaosy" + ".jpg"; if (File.Exists(picName)) { File.Delete(picName); } using (Stream stream = File.Create(picName)) { pE.Save(stream); } //拍照完成后关摄像头并刷新同时关窗体 if (videoSourcePlayer != null && videoSourcePlayer.IsRunning) { videoSourcePlayer.SignalToStop(); videoSourcePlayer.WaitForStop(); } this.Close(); } } catch (Exception ex) { MessageBox.Show("摄像头异常:" + ex.Message); } } private string GetImagePath() { string personImgPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + Path.DirectorySeparatorChar.ToString() + "PersonImg"; if (!Directory.Exists(personImgPath)) { Directory.CreateDirectory(personImgPath); } return personImgPath; } }}
阅读全文
0 0
- c# 关于aforgenet获取本地摄像头
- c#获取摄像头
- c# 获取 摄像头 实现录像
- c# 获取 摄像头 实现录像
- C#关于摄像头的使用
- C#获取本地IP
- C#获取本地计算机信息
- c# 获取本地路径
- 本地摄像头
- 在C#获取摄像头数据的程序
- Android 关于获取摄像头帧数据
- Android 关于获取摄像头帧数据
- Android 关于获取摄像头帧数据
- Android 关于获取摄像头帧数据
- Android 关于获取摄像头帧数据解码
- C#获取本地IP地址
- c# 获取本地Ip地址
- C#获取本地IP地址
- 6D-java-姜/sr
- Web开发发布环境:tomcat、Eclipse
- mybatis代码自动生成工具(maven方式)
- 给织梦的dede:channel增加可选择范围的属性
- Android Studio maven-metadata.xml 卡着不动原因和解决方法
- c# 关于aforgenet获取本地摄像头
- 织梦dedecms让dede:channel支持调用[field:seotitle/]
- Scala函数
- 关于tomcat Deployment中 带exploded和不带的区别
- FIS3学习笔记(二)
- 为什么定义数组时要定义好数组大小
- HBASE的备份策略(数据迁移)
- 垃圾收集算法
- 使用fsck修复文件系统错误