码迷,mamicode.com
首页 > Windows程序 > 详细

使用AForge.NET Framework打开摄像头并截图 C#

时间:2017-09-07 13:44:34      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:index   count   source   下载   sha   solution   bit   net   dex   

videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                    if (videoDevices.Count == 0)
                    {
                        MessageBox.Show("未检测到摄像头,请确认!");
                        return;
                    }
                    selectedDeviceIndex = 0;
                    videoSource = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头
                    int ResolutionIndex = 0;
                    for (int i = 0; i < videoSource.VideoCapabilities.Length; i++)
                    {
                        if (videoSource.VideoCapabilities[i].FrameSize.Width == 1600)  //1600*1200分辨率即可
                        {
                            ResolutionIndex = i;
                            break;
                        }
                    }
                    videoSource.VideoResolution = videoSource.VideoCapabilities[ResolutionIndex];
                    videoSourcePlayer1.VideoSource = videoSource;
                    // set NewFrame event handler
                    videoSourcePlayer1.Start();

 

下载库添加引用添加 

videoSourcePlayer
控件就不说了

代码操作很简单

但有可能部分usb摄像头不支持

截图
if (videoSource == null)
                                return;
                            Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();

  

使用AForge.NET Framework打开摄像头并截图 C#

标签:index   count   source   下载   sha   solution   bit   net   dex   

原文地址:http://www.cnblogs.com/jhlong/p/7488900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!