3

我正在使用 Visual Studio 2012 并使用 C#,我正在使用库 DirectShowLib 从我的网络摄像头拍照,但我只能拍一张照片,如果我尝试拍摄另一张照片,则会出现异常:

   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]中抛出异常

这条线DirectShowLib.DsError.ThrowExceptionForHR(Int32 hr)引起了我的注意,这是什么意思?我怎样才能解决这个问题?

4

1 回答 1

7

错误-2147023446是“系统资源不足,无法完成请求的服务” 0x800705AAERROR_NO_SYSTEM_RESOURCES(请参阅这篇文章和工具HRESULT,了解如何轻松方便地读取值)。

我会说您很可能正在尝试打开第二个管道而不先关闭。并且视频捕获设备是专门打开的,因此如果有另一个仍然处于活动状态,您将无法启动管道。错误代码正是暗示了这一点。

为了解决这个问题,您需要确保调用IMediaControl.Stop以前的过滤器图,并使用Marshal.ReleaseComObject.

于 2012-08-24T20:23:05.257 回答