最近在使用摄像头的时候,提示了这个 video device was unplugged错误
winform的形式,用了控件VideoSourcePlayer,下面是我的方法
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (videoDevices.Count != 0)
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);//连接摄像头。
selectedDeviceIndex = 0;
videoSource.VideoResolution = videoSource.VideoCapabilities[selectedDeviceIndex];
_vspTakePhoto.VideoSource = videoSource;
// set NewFrame event handler
_vspTakePhoto.Start();
}
else
{
throw new ApplicationException();
}
但是我不断的刷新(写了方法不断地打开关闭摄像头),然后就可以。
所以述求是:
1.怎么循环获取到成功为止,而不是我手动刷新。
2.是代码问题还是硬件设备的问题呢?