问题描述
我正在使用Visual Studio 2012并使用C#,正在使用DirectShowLib库从网络摄像头拍摄照片,但是我只能拍摄一张照片,如果尝试拍摄另一张照片,我会遇到异常:
I'm working on Visual Studio 2012 and using C#, I'm using the library DirectShowLib to take pictures from my webcam, but I can only take one picture, if I try to take another one I get an exception:
DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)
at SnapShot.Capture.SetupGraph(DsDevice dev, Int32 iWidth, Int32 iHeight, Int16 iBPP, Control hControl) in c:\Users\devel_000\Documents\Visual Studio 2012\Projects\ControlAcceso\ControlAcceso\Capture.cs:line 323
at SnapShot.Capture..ctor(Int32 iDeviceNum, Int32 iWidth, Int32 iHeight, Int16 iBPP, Control hControl) in c:\Users\devel_000\Documents\Visual Studio 2012\Projects\ControlAcceso\ControlAcceso\Capture.cs:line 86
at ControlAcceso.PhotoWindow..ctor() in c:\Users\devel_000\Documents\Visual Studio 2012\Projects\ControlAcceso\ControlAcceso\PhotoWindow.cs:line 32
at ControlAcceso.CheckWindow.pbPhoto_Click(Object sender, EventArgs e) in c:\Users\devel_000\Documents\Visual Studio 2012\Projects\ControlAcceso\ControlAcceso\CheckWindow.cs:line 108
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at ControlAcceso.Program.Main() in c:\Users\devel_000\Documents\Visual Studio 2012\Projects\ControlAcceso\ControlAcceso\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
我正在使用DxSnap示例 [链接] 到拍照.该异常会在SetupGraph [link]
I'm using the DxSnap example [link] to take the pictures. the exception is thrown in the method SetupGraph [link]
DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)
行引起了我的注意,这是什么意思?我该如何解决?
The line DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)
caught my attention, what does it mean? How can I fix this?
推荐答案
错误-2147023446
是0x800705AA
,ERROR_NO_SYSTEM_RESOURCES
系统资源不足,无法完成请求的服务." (请参阅这篇文章和工具,以轻松便捷的方式读取HRESULT
值).
The error -2147023446
is 0x800705AA
, ERROR_NO_SYSTEM_RESOURCES
"Insufficient system resources exist to complete the requested service." (see this post and tool on reading HRESULT
values easily and in convenient way).
我会说您很可能在尝试打开第二条管道而不先关闭.视频捕获设备是专门打开的,因此,如果还有另一个仍处于活动状态,则您将无法启动管道.错误代码正好说明了这一点.
I would say most likely you are trying to open second pipeline without closing first. And video capture devices are opened exclusively, hence you cannot start a pipeline if there is another one still active. The error code is suggesting exactly this.
要变通解决此问题,您需要确保在上一个过滤器图上调用IMediaControl.Stop
,并使用Marshal.ReleaseComObject
释放不再需要的COM接口.
In order to work this around, you need to make sure you call IMediaControl.Stop
on previous filter graph, and release COM interfaces you don't need anymore with Marshal.ReleaseComObject
.
这篇关于DirectShowLib-使用网络摄像头不能拍摄多张照片.得到“存在不足的系统资源来完成所请求的服务".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!