From 3eb4cfec9a84aeb6a395983b9b01cfc88084d2b9 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 18 Apr 2019 12:05:23 +0100 Subject: [PATCH] Windows: Rescale image in createSnapshotOfNativeWindow() to be in logical pixels --- .../native/juce_win32_Windowing.cpp | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 655a7e27cd..c3ddad08e7 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -845,15 +845,32 @@ Image createSnapshotOfNativeWindow (void* nativeWindowHandle) { auto hwnd = (HWND) nativeWindowHandle; - auto r = getWindowRect (hwnd); - const int w = r.right - r.left; - const int h = r.bottom - r.top; + auto r = convertPhysicalScreenRectangleToLogical (rectangleFromRECT (getWindowRect (hwnd)), hwnd); + const int w = r.getWidth(); + const int h = r.getHeight(); auto nativeBitmap = new WindowsBitmapImage (Image::RGB, w, h, true); Image bitmap (nativeBitmap); HDC dc = GetDC (hwnd); - BitBlt (nativeBitmap->hdc, 0, 0, w, h, dc, 0, 0, SRCCOPY); + + if (isPerMonitorDPIAwareProcess()) + { + auto scale = getScaleFactorForWindow (hwnd); + auto prevStretchMode = SetStretchBltMode (nativeBitmap->hdc, HALFTONE); + SetBrushOrgEx (nativeBitmap->hdc, 0, 0, NULL); + + StretchBlt (nativeBitmap->hdc, 0, 0, w, h, + dc, 0, 0, roundToInt (w * scale), roundToInt (h * scale), + SRCCOPY); + + SetStretchBltMode (nativeBitmap->hdc, prevStretchMode); + } + else + { + BitBlt (nativeBitmap->hdc, 0, 0, w, h, dc, 0, 0, SRCCOPY); + } + ReleaseDC (hwnd, dc); return SoftwareImageType().convert (bitmap);