Search code examples
c++wxwidgets

Creating a bitmap using wxBitmap::NewFromPNGData method causes assert in wxWidgets 3.0


I created a wxBitmap using wxBitmap::NewFromPNGData and IsOk() method returned false. My code is

static const unsigned char image_png[] = ...;
auto bitmap = wxBitmap::NewFromPNGData(image_png, WXSIZEOF(image_png));

bitmap.IsOk() returns false What is wrong with this code? Is there another way to create bitmaps from hardcoded pngs?


Solution

  • Unless your wxWidgets was built without PNG support (which is very unlikely, as you need to explicitly disable it for this, it is enabled by default), the only explanation is the obvious one: your image_png doesn't contain valid data in PNG format. Did you check that it hasn't got corrupted somehow? How did you create image_png? Did you use misc/scripts/png2c.py from wxWidgets sources or some other way?