Browse Source

Windows: Rescale image in createSnapshotOfNativeWindow() to be in logical pixels

tags/2021-05-28
ed 6 years ago
parent
commit
3eb4cfec9a
1 changed files with 21 additions and 4 deletions
  1. +21
    -4
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp

+ 21
- 4
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -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);


Loading…
Cancel
Save