Aforge 视频 - 相机被其他设备使用
Posted
技术标签:
【中文标题】Aforge 视频 - 相机被其他设备使用【英文标题】:Aforge video - Camera is use by another device 【发布时间】:2021-01-01 20:03:42 【问题描述】:我正在使用 Aforge Video 访问我电脑的摄像头。好的和工作的东西,但我现在的问题是当另一个应用程序首先使用相机时。即使相机被另一个应用程序使用,Aforge Video 的 Start() 方法也不会失败。有没有办法检查相机是否已经在 AForge Video 中使用?
【问题讨论】:
如果它没有失败,那有什么问题呢? 你知道当相机被另一个应用程序使用时,它不能被应用程序使用。那就是问题所在。如果相机被另一个应用程序使用,当你的 Start 方法没有失败时,你将如何通知用户相机被另一个应用程序使用。 啊,现在我明白了。所以Start
方法“似乎”可以工作,但实际上你并没有得到任何图片,没有例外或任何东西......
是的@Fildor,这正是发生的事情。
我找到了一种解决方法。我只是添加检查是否调用了 newframe 事件。
【参考方案1】:
这是我为解决此问题而实施的解决方法:
private async void StartCameraAsync()
if (SFilterInfo != null)
VideoCaptureDevice = new VideoCaptureDevice(SFilterInfo.MonikerString);
VideoCaptureDevice.NewFrame += new NewFrameEventHandler(VideoCaptureDevice_NewFrame);
VideoCaptureDevice.Start();
await Task.Delay(1000);
//Set false when video started
IsImageGrab =false;
private void VideoCaptureDevice_NewFrame(object sender, NewFrameEventArgs eventArgs)
try
//Set true so that you will know that images in the camera is received
IsImageGrab = true;
System.Drawing.Image img = (Bitmap)eventArgs.Frame.Clone();
MemoryStream ms = new MemoryStream();
img.Save(ms, ImageFormat.Bmp);
ms.Seek(0, SeekOrigin.Begin);
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = ms;
bi.EndInit();
bi.Freeze();
catch (Exception ex)
【讨论】:
以上是关于Aforge 视频 - 相机被其他设备使用的主要内容,如果未能解决你的问题,请参考以下文章
AForge.NET:未触发 NewFrameEventHandler 参数方法