Page 1 of 1

...msw\bitmap.cpp(842): assert ""image.IsOk()"" failed in wxBitMap::CreateFromImage(): invalid image [wxWidgets 3.1.3]

Posted: Fri Mar 20, 2020 9:49 pm
by var_null
Hello, the following code compiles and runs fine under Linux:

Image

Code: Select all

staticboxsizer_Logo = new wxStaticBoxSizer(wxHORIZONTAL, Panel1, wxEmptyString);
    staticbitmap_logo = new wxStaticBitmap(Panel1, ID_STATICBITMAP2, wxBitmap(wxImage(_T("C:\Logo_0.png"))), wxDefaultPosition, wxDefaultSize, 0, _T("ID_STATICBITMAP2"));
    staticboxsizer_Logo->Add(staticbitmap_logo, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 0);
Under Windows it compiles fine too, however when I run the .exe I get the following error:

Code: Select all

C:\wxWidgets\src\msw\bitmap.cpp(842): assert ""image.IsOk()"" failed in wxBitMap::CreateFromImage(): invalid image
What can I do so the logo (265x46 px) also shows fine under Windows?

Thanks

Re: ...msw\bitmap.cpp(842): assert ""image.IsOk()"" failed in wxBitMap::CreateFromImage(): invalid image [wxWidgets 3.1.

Posted: Fri Mar 20, 2020 10:41 pm
by doublemax
The main problem is probably that you need to escape the backslash.

Code: Select all

"C:\\Logo_0.png"
But how could that path have worked under Linux?

But using an absolute path here is not the best option anyway. Look into wxStandardPaths. https://docs.wxwidgets.org/trunk/classw ... paths.html

Re: ...msw\bitmap.cpp(842): assert ""image.IsOk()"" failed in wxBitMap::CreateFromImage(): invalid image [wxWidgets 3.1.

Posted: Fri Mar 20, 2020 10:52 pm
by var_null
Thank you very much, never imagined I just needed another "\", it works great now
But how could that path have worked under Linux?
The Linux version has a different path