mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Fixed an issue in the DX9ScreenCapture caused by windows-dpi-scaling
This commit is contained in:
parent
270e5963a9
commit
4be8735ca6
@ -2,6 +2,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Media;
|
||||
using Microsoft.Win32;
|
||||
using SharpDX.Direct3D9;
|
||||
|
||||
namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
@ -15,6 +16,14 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
Width = Screen.PrimaryScreen.Bounds.Width;
|
||||
Height = Screen.PrimaryScreen.Bounds.Height;
|
||||
|
||||
//DarthAffe 08.04.2017: Fix for systems 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);
|
||||
}
|
||||
|
||||
var presentParams = new PresentParameters(Width, Height)
|
||||
{
|
||||
Windowed = true,
|
||||
@ -24,7 +33,7 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.ScreenCapturing
|
||||
_device = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero,
|
||||
CreateFlags.SoftwareVertexProcessing, presentParams);
|
||||
_surface = Surface.CreateOffscreenPlain(_device, Width, Height, Format.A8R8G8B8, Pool.Scratch);
|
||||
_buffer = new byte[Width*Height*4];
|
||||
_buffer = new byte[Width * Height * 4];
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -43,6 +52,19 @@ namespace Artemis.Profiles.Layers.Types.AmbientLight.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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user