视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

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

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();

  

posted @ 2017-09-07 11:39  jhlong  阅读(3483)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用