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

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
var_null
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu Feb 27, 2020 6:44 pm

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

Post by var_null » Fri Mar 20, 2020 9:49 pm

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

User avatar
doublemax
Moderator
Moderator
Posts: 14977
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax » Fri Mar 20, 2020 10:41 pm

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
Use the source, Luke!

var_null
Earned a small fee
Earned a small fee
Posts: 14
Joined: Thu Feb 27, 2020 6:44 pm

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

Post by var_null » Fri Mar 20, 2020 10:52 pm

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

Post Reply