星空网 > 软件开发 > ASP.net

C# 使用AForge调用笔记本摄像头拍照

vs2012  winform

连接摄像头设备,这里需要引入

C# 使用AForge调用笔记本摄像头拍照

代码:

 

 

using AForge;using AForge.Controls;using AForge.Imaging;using AForge.Video;using AForge.Video.DirectShow;

在工具箱中还需要添加AForge.Control,然后找到VideoSourcePlayer这个控件添加到界面上

直接找到dll拖拽到工具箱就可以了(工具箱先建一个选项)

C# 使用AForge调用笔记本摄像头拍照

将在camera里面出现很多控件,找到videoSourcePlayer,拖拽至form窗体

 

C# 使用AForge调用笔记本摄像头拍照

 

然后完成了基本设置

定义全局变量

FilterInfoCollection videoDevices;
VideoCaptureDevice videoSource;
public int selectedDeviceIndex = 0;

然后连接摄像头

 1 private void btn_getdevice_Click(object sender, EventArgs e) 2     { 3       videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice); 4       selectedDeviceIndex = 0; 5       videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。 6       videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex]; 7       videoSourcePlayer1.VideoSource = videoSource; 8       // set NewFrame event handler 9       videoSourcePlayer1.Start(); 10     }   

 

拍照:

1 private void button1_Click(object sender, EventArgs e)2     {3       if (videoSource == null)4         return;5       Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();6       string fileName = "54250.jpg";//DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-ff") + ".jpg";7       bitmap.Save(@"E:\temp\" + fileName, ImageFormat.Jpeg);8       bitmap.Dispose();9     }

 

 

 

这样就完成了拍照功能

 

 

效果图

C# 使用AForge调用笔记本摄像头拍照

 

这是一个关于aforge讨论的群,可以加进来互相讨论,我不是群主不是管理员!

205584568,希望不要见怪!

 




原标题:C# 使用AForge调用笔记本摄像头拍照

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

深圳到菲律宾海运费用:https://www.goluckyvip.com/tag/97270.html
海运菲律宾整柜:https://www.goluckyvip.com/tag/97271.html
广州到菲律宾海运费用:https://www.goluckyvip.com/tag/97272.html
菲律宾海运多少天:https://www.goluckyvip.com/tag/97274.html
菲律宾海运价格表:https://www.goluckyvip.com/tag/97275.html
菲律宾海运拼箱:https://www.goluckyvip.com/tag/97276.html
桂林酒店销售多少钱 桂林旅游宾馆价格:https://www.vstour.cn/a/410227.html
十里银滩旅游攻略玩什么住哪里怎么去?:https://www.vstour.cn/a/410228.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流