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

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM