简体   繁体   中英

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM