Handle scale factor in another wxMSW wxBitmap ctor taking wxDC
This is similar to db6d565fad
(Handle wxDC scale factor in wxBitmap ctor
taking wxDC in wxMSW, 2022-04-10), but for the constructor taking
wxImage and wxDC -- it should also use the DC scale factor, even if it
is not used for scaling the bitmap size in this case.
Add a unit test checking for this.
This commit is contained in:
parent
558a300996
commit
b185186ebf
@ -856,7 +856,12 @@ bool wxBitmap::CreateFromImage(const wxImage& image, const wxDC& dc)
|
||||
wxCHECK_MSG( dc.IsOk(), false,
|
||||
wxT("invalid HDC in wxBitmap::CreateFromImage()") );
|
||||
|
||||
return CreateFromImage(image, -1, dc.GetHDC());
|
||||
if ( !CreateFromImage(image, -1, dc.GetHDC()) )
|
||||
return false;
|
||||
|
||||
GetBitmapData()->m_scaleFactor = dc.GetContentScaleFactor();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if wxUSE_WXDIB
|
||||
|
@ -1726,6 +1726,16 @@ TEST_CASE("Bitmap::ScaleFactor", "[bitmap][dc][scale]")
|
||||
wxBitmap bmp2(4, 4, dc);
|
||||
CHECK( bmp2.GetScaleFactor() == 2 );
|
||||
CHECK( bmp2.GetSize() == wxSize(8, 8) );
|
||||
|
||||
#ifdef __WXMSW__
|
||||
// A compatible bitmap created from wxImage and this DC should also inherit
|
||||
// the same scale factor, but its size should be still the same as that of
|
||||
// the image.
|
||||
wxImage img(16, 16);
|
||||
wxBitmap bmp3(img, dc);
|
||||
CHECK( bmp3.GetScaleFactor() == 2 );
|
||||
CHECK( bmp3.GetSize() == wxSize(16, 16) );
|
||||
#endif // __WXMSW__
|
||||
}
|
||||
|
||||
#endif // ports with scaled bitmaps support
|
||||
|
Loading…
Reference in New Issue
Block a user