Obviously, the signature of wxStaticBitmap methods changed between 3.1.6 and 3.1.7, the latter using wxBitmapBundle where the former had wxBitmap.
As I was still not sure what is the issue, I tried comparing 3.1.6, 3.1.7, and a week old GIT master.
I had 100x100 px PNG bitmap, loaded from resource to wxStaticBitmap in a PMv2 DPI-aware application on Win10 21H2 system where the primary monitor is at 125%DPI and the secondary one unscaled.
The bitmap in wxStaticBitmap did not change size in any version, i.e., I could not observe any difference.
Code (uses default wxStaticBitmap ScaleMode)
Code: Select all
#include <wx/wx.h>
#include <wx/statbmp.h>
class MyFrame : public wxFrame
{
public:
MyFrame () : wxFrame(nullptr, wxID_ANY, "Test")
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
wxBitmap bmp = wxBITMAP_PNG(mybitmap);
m_staticBmp = new wxStaticBitmap(this, wxID_ANY, bmp);
m_staticBmp->SetBackgroundColour(*wxRED);
mainSizer->Add(m_staticBmp, wxSizerFlags(1).Expand());
wxTextCtrl* logCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);
wxLog::SetActiveTarget(new wxLogTextCtrl(logCtrl));
mainSizer->Add(logCtrl, wxSizerFlags(1).Expand());
SetSizer(mainSizer);
wxLogMessage("wxWidgets version: %s", wxVERSION_NUM_DOT_STRING);
LogBitmapSize(bmp, "PNG resource bitmap");
Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& e) { e.Skip(); LogBitmapSize(m_staticBmp->GetBitmap(), "wxStaticBitmap bitmap");});
CallAfter([this] { LogBitmapSize(m_staticBmp->GetBitmap(), "wxStaticBitmap bitmap");} );
}
private:
wxStaticBitmap* m_staticBmp;
void LogBitmapSize(const wxBitmap& bmp, const wxString& bmpIdent)
{
const wxSize size = bmp.GetSize();
wxLogMessage("%s size: %d x %d", bmpIdent, size.x, size.y);
}
};
class MyApp : public wxApp
{
public:
bool OnInit() override
{
wxInitAllImageHandlers();
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
Resource file (wxUSE_RC_MANIFEST and wxUSE_DPI_AWARE_MANIFEST=2 are set in the resource compiler definitions in the MSVS project)
Code: Select all
#include "wx/msw/wx.rc"
MYBITMAP RCDATA "mybitmap.png"
When wxStaticBitmap was allowed to expand, in all versions the control expanded but the bitmap remained centered at the original size.
I did not measure if the bitmap displayed is actually 100x100, I blindly trusted what wxWidgets reported. It is also possible that wxStaticBitmap returns the bitmap used when constructing it and not the one it is actually using, but...
EDIT
I tried changing my DPI scaling from 125% to 200%. After doing this, the bitmap from wxStaticBitmap resizes from 100x100 to 200x200, the scaling is probably done in some steps, e.g. integer multiplies only. Still, the bitmap scaled in all three wxWidgets versions the same.