wxWidgets, imagemagic and png

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

wxWidgets, imagemagic and png

Post by Joelito »

I'm trying to convert png to header code with ImageMagick. Does anyone had succesfully use it. Because testing 3 image gives me on my executable startup "This is not a image PNG" message. The code is simple:

Code: Select all

convert close.png close.h
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux x86_64 with xfce desktop & wxgtk{2,3}-3.0.5.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWidgets, imagemagic and png

Post by doublemax »

Please show an example of the generated header file and the code that's supposed to load the image.

https://wiki.wxwidgets.org/Embedding_PNG_Images
Use the source, Luke!
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

Re: wxWidgets, imagemagic and png

Post by Joelito »

Sorry for the delay.

1.- This is the test icon stop.png
Image
2.- My convert version:

Code: Select all

convert -version
outputs:
Version: ImageMagick 6.9.9-23 Q16 x86_64 2017-11-12 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenCL OpenMP
Delegates (built-in): bzlib cairo fontconfig freetype gslib jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps raw rsvg tiff webp wmf x xml zlib
3.- imagemagick command from png to C/C++ header file

Code: Select all

convert Stop.png stop_png.h 
Contents of stop_png.h, outputs this -> nopaste.xyz
4.- After editing the header to fit the wxBITMAP_PNG needs, from
static const unsigned char MagickImage[]
to
static const unsigned char stop_png[]
The test code example:

Code: Select all

#include "stop_png.h"
// ...
wxImage::AddHandler(new wxPNGHandler);
// ...
wxButton *stop_button = new wxButton(panel, wxID_STOPBUTTON, _("&Find"));
stop_button->SetBitmap(wxBITMAP_PNG(stop));
Get the warning:
Image
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux x86_64 with xfce desktop & wxgtk{2,3}-3.0.5.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWidgets, imagemagic and png

Post by doublemax »

Try wxBITMAP_PNG_FROM_DATA instead of wxBITMAP_PNG
Use the source, Luke!
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

Re: wxWidgets, imagemagic and png

Post by Joelito »

Code: Select all

file_button->SetBitmap(wxBITMAP_PNG_FROM_DATA(stop));
Same warning :(
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux x86_64 with xfce desktop & wxgtk{2,3}-3.0.5.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWidgets, imagemagic and png

Post by doublemax »

The header file stop_png.h and the PNG you posted are definitely not the same. In the PNG, the first four bytes are 0x89, 0x50, 0x4e, 0x47 which is the PNG marker.

So i'd say the error message is correct, the header file does not contain a valid PNG file. It seems the tool converted it into PNM.
Use the source, Luke!
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

Re: wxWidgets, imagemagic and png

Post by Joelito »

yeah, right now I'm using wxInclude and bin2c and both produce correct header files.
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux x86_64 with xfce desktop & wxgtk{2,3}-3.0.5.
Post Reply