From 0b92068fe69a8def446bc23f4fde0fc97eb28f1b Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 8 Apr 2017 15:17:36 +0200 Subject: [PATCH] Fixed DPI-scaling problem in the Ambilight-Example --- .../ScreenCapturing/DX9ScreenCapture.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Examples/Ambilight/Example_Ambilight_full/TakeAsIs/ScreenCapturing/DX9ScreenCapture.cs b/Examples/Ambilight/Example_Ambilight_full/TakeAsIs/ScreenCapturing/DX9ScreenCapture.cs index b4cadce..5c212f1 100644 --- a/Examples/Ambilight/Example_Ambilight_full/TakeAsIs/ScreenCapturing/DX9ScreenCapture.cs +++ b/Examples/Ambilight/Example_Ambilight_full/TakeAsIs/ScreenCapturing/DX9ScreenCapture.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Windows.Media; +using Microsoft.Win32; using SharpDX; using SharpDX.Direct3D9; @@ -27,6 +28,14 @@ namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing Width = (int)System.Windows.SystemParameters.PrimaryScreenWidth; Height = (int)System.Windows.SystemParameters.PrimaryScreenHeight; + //DarthAffe 08.04.2017: Fix for system using windows-scaling. The primary screen size is reported 'wrong'. + double scaling = GetScaling(); + if (Math.Abs(scaling - 1.0) > 0.01) + { + Width = (int)(Width / scaling); + Height = (int)(Height / scaling); + } + PresentParameters presentParams = new PresentParameters(Width, Height) { Windowed = true, @@ -42,6 +51,19 @@ namespace Example_Ambilight_full.TakeAsIs.ScreenCapturing #region Methods + private double GetScaling() + { + try + { + int currentDpi = (int)Registry.GetValue("HKEY_CURRENT_USER\\Control Panel\\Desktop", "LogPixels", 96); + return 96.0 / currentDpi; + } + catch + { + return 1.0; + } + } + public byte[] CaptureScreen() { _device.GetFrontBufferData(0, _surface);