From f35a9662fdd2bf081809ad0080088b74df5cf801 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 7 Sep 2018 11:09:00 -0400 Subject: [PATCH] Fix ScreenCapture to include negative offset monitors. --- .../spark/view/Utility/ScreenCapture.cs | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/client/spark/view/Utility/ScreenCapture.cs b/src/client/spark/view/Utility/ScreenCapture.cs index 7e75afff9..ba0137be4 100644 --- a/src/client/spark/view/Utility/ScreenCapture.cs +++ b/src/client/spark/view/Utility/ScreenCapture.cs @@ -48,20 +48,23 @@ namespace mbts.ui.utility return null; } - static (int width,int height) screen_size() { + static Int32Rect screen_size() { var config = Configuration.get(); - double width = SystemParameters.VirtualScreenWidth * config.dpi_ratio; - double height = SystemParameters.VirtualScreenHeight * config.dpi_ratio; - return ((int)width, (int)height); + var dpi = config.dpi_ratio; + return new Int32Rect( + (int)(SystemParameters.VirtualScreenLeft * dpi), + (int)(SystemParameters.VirtualScreenTop * dpi), + (int)(SystemParameters.VirtualScreenWidth * dpi), + (int)(SystemParameters.VirtualScreenHeight * dpi)); } private static BitmapSource capture() { - (int width, int height) = screen_size(); + var screen = screen_size(); IntPtr screen_dc = NativeMethods.GetDC(IntPtr.Zero); IntPtr mem_dc = NativeMethods.CreateCompatibleDC(screen_dc); - IntPtr hbitmap = NativeMethods.CreateCompatibleBitmap(screen_dc, width, height); + IntPtr hbitmap = NativeMethods.CreateCompatibleBitmap(screen_dc, screen.Width, screen.Height); NativeMethods.SelectObject(mem_dc, hbitmap); - bool success = NativeMethods.BitBlt(mem_dc, 0, 0, width, height, screen_dc, 0, 0); + bool success = NativeMethods.BitBlt(mem_dc, 0, 0, screen.Width, screen.Height, screen_dc, screen.X, screen.Y); BitmapSource bsource = Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); NativeMethods.DeleteObject(hbitmap); NativeMethods.ReleaseDC(IntPtr.Zero, screen_dc); @@ -71,13 +74,13 @@ namespace mbts.ui.utility private static BitmapSource capture(int width_dest, int height_dest) { - (int width_src, int height_src) = screen_size(); + var screen = screen_size(); IntPtr screen_dc = NativeMethods.GetDC(IntPtr.Zero); IntPtr mem_dc = NativeMethods.CreateCompatibleDC(screen_dc); IntPtr hbitmap = NativeMethods.CreateCompatibleBitmap(screen_dc, width_dest, height_dest); NativeMethods.SelectObject(mem_dc, hbitmap); NativeMethods.SetStretchBltMode(mem_dc, 4/*HALFTONE*/); - bool success = NativeMethods.StretchBlt(mem_dc, 0, 0, width_dest, height_dest, screen_dc, 0, 0, width_src, height_src); + bool success = NativeMethods.StretchBlt(mem_dc, 0, 0, width_dest, height_dest, screen_dc, screen.X, screen.Y, screen.Width, screen.Height); BitmapSource bsource = Imaging.CreateBitmapSourceFromHBitmap(hbitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); NativeMethods.DeleteObject(hbitmap); NativeMethods.ReleaseDC(IntPtr.Zero, screen_dc);