mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Windows: Rescale image in createSnapshotOfNativeWindow() to be in logical pixels
This commit is contained in:
parent
e41bb41a1e
commit
3eb4cfec9a
1 changed files with 21 additions and 4 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue