IVMRWindowlessControl.RepaintVideo导致尝试除以零

时间:2017-04-25 04:38:47

标签: c# directshow directshow.net

我使用Directshow.NET开发了一个C#应用程序来显示相机预览。一切都在几乎所有操作系统上运行良好,但是在一些Windows OS 10机器上(并非每个win OS 10,只有其中一些)预览因Attempted to divide by zero. hr = vmr9Control.RepaintVideo(hControl.Handle, gHDC);内的Paint而失败} Control的事件。

我经常搜索以查找此异常的原因,即使我格式化了其中一台机器,但问题仍然存在。另外,根据观察,在预览的第一次尝试之后,在预览的第一次尝试之后,这个例外将不会出现。停止预览会导致此异常。

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 个答案:

答案 0 :(得分:1)

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

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

设备管理器

中删除显示驱动程序

一个。点击开始按钮打开设备管理器,或在搜索框中输入设备管理器

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

℃。查找显示适配器驱动程序,右键单击它并选择卸载

d。 重新启动计算机。

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

相关问题