2017-04-25 69 views
0

分我已经与Directshow.NET一个C#应用程序,以显示相机的预览。一切都进展顺利,几乎在每一个操作系统,但在某些Windows 10操作系统的机器(不是每赢OS 10,只是其中的一些)预览进去Paint事件Control在行hr = vmr9Control.RepaintVideo(hControl.Handle, gHDC);失败,原因是异常Attempted to divide by zero.IVMRWindowlessControl.RepaintVideo导致试图通过零

我搜索了很多找到这个异常的原因,连我formattted机器之一,但问题仍然存在。同样根据观察,这个例外不会在第一次尝试预览时发生,在5-6次迭代后,预览&停止预览会导致此异常。

private void SetupGraph(DsDevice dev, Control hControl) 
{ 
... 
vmr9Control = (IVMRWindowlessControl)vmr9preview; 
vmr9Control.SetVideoClippingWindow(hControl.Handle); 
vmr9Control.SetAspectRatioMode(VMRAspectRatioMode.None); 
hControl.Paint += new PaintEventHandler(hControl_Paint); 
... 
} 

[System.Security.Permissions.SecurityPermission(
System.Security.Permissions.SecurityAction.LinkDemand, Flags = 
System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)] 
void hControl_Paint(object sender, PaintEventArgs e) 
{ 
    if (isPreviewstarted && vmr9Control != null) 
    { 
     int hr; 
     IntPtr gHDC = e.Graphics.GetHdc(); 
     hr = vmr9Control.RepaintVideo(hControl.Handle, gHDC); 
     DsError.ThrowExceptionForHR(hr); 
     e.Graphics.ReleaseHdc(gHDC); 
    }    
} 

回答

1

我建议你卸载重新安装显卡驱动程序

步骤:卸载重新安装显示驱动程序

设备管理器中删除显示驱动器:

一个。通过点击搜索框中的开始按钮类型设备管理器打开设备管理器

湾如果提示您输入管理员密码或确认,请键入密码或提供确认。

c。外观为显示适配器驱动程序,右键单击它并选择卸载。 d)。 重新启动电脑。

即重新启动时,Windows 10应自动重新安装驱动程序。