开发者

How does one disable hardware acceleration in wpf?

What is the proce开发者_开发技巧dure 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?


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)


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.


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).


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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜