如何在 WPF 中禁用硬件加速?

发布于 2024-08-20 01:57:35 字数 106 浏览 3 评论 0原文

在 WPF 中禁用硬件加速的步骤是什么?到底是什么?它是 Windows 设置、Visual Studio 设置还是您在 WPF 项目代码中更改的内容?它只会影响您正在运行的程序还是会影响整个系统?

What is the procedure for disabling hardware acceleration in WPF? What is it exactly? Is it a Windows setting, a Visual Studio setting, or something you alter in the code of your WPF project? Will it affect only the program you're running or will it be system-wide?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

渔村楼浪 2024-08-27 01:57:35

从 .Net 3.5 SP1 开始,您可以在 Window 级别禁用它。

public partial class MyWindow : Window
{
    public MyWindow()
        : base()
    {
        InitializeComponent();
    }

    protected override void OnSourceInitialized(EventArgs e)
    {
        var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

        if (hwndSource != null)
            hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

        base.OnSourceInitialized(e);
    }
}

或者您可以订阅窗口的 SourceInitialized 事件并执行相同的操作。

或者,您可以在进程级别设置

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

优先顺序对于软件渲染是:

  1. DisableHWAcceleration 注册表项
  2. ProcessRenderMode
  3. RenderMode(每个目标)

You can disable it on a Window level starting from .Net 3.5 SP1.

public partial class MyWindow : Window
{
    public MyWindow()
        : base()
    {
        InitializeComponent();
    }

    protected override void OnSourceInitialized(EventArgs e)
    {
        var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

        if (hwndSource != null)
            hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

        base.OnSourceInitialized(e);
    }
}

or you can subscribe to SourceInitialized event of the window and do the same.

Alternatively you can set it on Process level:

RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

The precedence order for software rendering is:

  1. DisableHWAcceleration registry key
  2. ProcessRenderMode
  3. RenderMode (per-target)
叹倦 2024-08-27 01:57:35

它是机器范围的注册表设置。请参阅图形渲染注册表设置在 WPF 文档中了解注册表项以及与自定义 WPF 呈现相关的其他详细信息。

列出的关键是:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration

MSDN 文档对于 .NET 4.5“不可用”,因此这可能是一个仅适用于 4.0 或更低版本的已弃用选项。

It is a machine-wide registry setting. See Graphics Rendering Registry Settings in the WPF docs for the registry key and other details relating to customizing WPF rendering.

The key listed is:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Avalon.Graphics\DisableHWAcceleration

The MSDN document is "not available" for .NET 4.5, so this may be a depricated option that only works in 4.0 or below.

蓝礼 2024-08-27 01:57:35

在版本 4.0 中,您还可以使用 RenderOptions.ProcessRenderMode 来设置进程范围首选项 (http://msdn.microsoft.com/en-us/library/system.windows.media.renderoptions.processrendermode.aspx)。

In version 4.0, you can also use RenderOptions.ProcessRenderMode to set a process wide preference (http://msdn.microsoft.com/en-us/library/system.windows.media.renderoptions.processrendermode.aspx).

快乐很简单 2024-08-27 01:57:35

您还可以通过在 MainWindow 中添加以下代码来禁用 WPF 应用程序中的硬件加速。

protected override void OnSourceInitialized(EventArgs e)
{
    var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

    if (hwndSource != null)
        hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

    base.OnSourceInitialized(e);
}

这解决了我的 TeamViewer 问题。

来源:
如何在 wpf 中禁用硬件加速?

You can also disble hardware acceleration in WPF App by adding in MainWindow the following code.

protected override void OnSourceInitialized(EventArgs e)
{
    var hwndSource = PresentationSource.FromVisual(this) as HwndSource;

    if (hwndSource != null)
        hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;

    base.OnSourceInitialized(e);
}

This solved my issue with TeamViewer.

Source:
How does one disable hardware acceleration in wpf?

倦话 2024-08-27 01:57:35

这是系统范围的设置,从桌面右键单击弹出菜单,单击属性,然后在其中查找视频设置以禁用硬件加速,或者可能有一个用于图形设置的系统托盘图标。这是系统范围的而不是本地的。

That is a system wide setting, from the desktop, right click to bring up a popup menu, click on properties, and look around in there for the video settings to disable Hardware acceleration or that there may be a system tray icon for the graphics settings. This is system wide and not local.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文