From ab605398107b153d89305d494e12415166f848cc Mon Sep 17 00:00:00 2001 From: Daniel Kulp Date: Mon, 22 Feb 2016 02:32:19 +0100 Subject: [PATCH] Return correctly scaled bitmaps from wxDC::GetAsBitmap() in wxOSX Use the scale used by the DC itself, i.e. the scale factor of the window it's associated with. Closes #17302. --- src/osx/cocoa/utils.mm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index d66cf5597b..02c18c47f9 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -586,7 +586,9 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const if (!m_window) return wxNullBitmap; - wxBitmap bitmap(subrect ? subrect->GetSize() : m_window->GetSize()); + const wxSize bitmapSize(subrect ? subrect->GetSize() : m_window->GetSize()); + wxBitmap bitmap; + bitmap.CreateScaled(bitmapSize.x, bitmapSize.y, -1, m_contentScaleFactor); NSView* view = (NSView*) m_window->GetHandle(); if ( [view isHiddenOrHasHiddenAncestor] == NO ) @@ -601,6 +603,12 @@ wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const CGImageRef cgImageRef = (CGImageRef)[rep CGImage]; CGRect r = CGRectMake( 0 , 0 , CGImageGetWidth(cgImageRef) , CGImageGetHeight(cgImageRef) ); + + // The bitmap created by wxBitmap::CreateScaled() above is scaled, + // so we need to adjust the coordinates for it. + r.size.width /= m_contentScaleFactor; + r.size.height /= m_contentScaleFactor; + // since our context is upside down we dont use CGContextDrawImage wxMacDrawCGImage( (CGContextRef) bitmap.GetHBITMAP() , &r, cgImageRef ) ; }