Page 1 of 1

How to compile PNG into exec to use it in wxIcon as XPM?

Posted: Wed Jan 11, 2006 4:16 pm
by kornerr
I.e. I can

Code: Select all

include "some.xpm"
and then wxIcon (some_xpm);
How to do the same thing with PNG? Or other format?

Thanks.

Re: How to compile PNG into exec to use it in wxIcon as XPM?

Posted: Wed Jan 11, 2006 4:42 pm
by ssigala
kornerr wrote: How to do the same thing with PNG? Or other format?
You should find enough information at:
http://wiki.wxwidgets.org/wiki.pl?Embedding_PNG_Images

Posted: Thu Jan 12, 2006 6:20 am
by kornerr
I've run bin2c, but I still can't use this "c image" in wxBitmapButton:

Code: Select all

 wxBitmapButton *btn = new wxBitmapButton (this, -1, wxImage (c_image));
Also, this

Code: Select all

wxImage::AddHandler (wxPNGHandler);
doesn't work. GCC says there's parse error before ");"
I tried wxInitAllImageHandlers ();, but button has no image.

Thanks.

PS: test.tar.bz2.doc
(remove ".doc" from filename)

Posted: Thu Jan 12, 2006 7:49 am
by upCASE
You should read the stuff in the wiki under "Including". You'll need a wxMemoryStream to "load" the PNG. What you do is assign the data directly, but this only works for XPM, not PNG.

Posted: Thu Jan 12, 2006 1:07 pm
by kornerr
So there's no way to embed PNG into my executable like XPM :(

Posted: Thu Jan 12, 2006 2:12 pm
by ssigala
kornerr wrote:I've run bin2c, but I still can't use this "c image" in wxBitmapButton:

Code: Select all

 wxBitmapButton *btn = new wxBitmapButton (this, -1, wxImage (c_image));
You should do something like:

Code: Select all

wxMemoryInputStream istream(c_image, sizeof c_image);
wxImage myimage(istream, wxBITMAP_TYPE_PNG);
 wxBitmapButton *btn = new wxBitmapButton (this, -1, myimage);
Also, this

Code: Select all

wxImage::AddHandler (wxPNGHandler);
doesn't work. GCC says there's parse error before ");"
Please note the "new" keyword:

Code: Select all

wxImage::AddHandler(new wxPNGHandler);

Posted: Thu Jan 12, 2006 4:25 pm
by kornerr
I've done:

Code: Select all

wxMemoryInputStream input_stream (button_close_small_png, sizeof (button_close_small_png));
wxImage btn_img (input_stream, wxBITMAP_TYPE_PNG);
wxBitmapButton *btn = new wxBitmapButton (this, -1, wxBitmap (btn_img));
But when I run app, I see the warning:

Code: Select all

No image handler for type 15 defined.
and there's no image at the button.

Thanks.

PS: test.tar.bz2.doc
(remove ".doc" from filename)

Posted: Sat Jan 14, 2006 12:14 am
by travfar
how about xrc, compile the xrc file into a cpp file and wxrc will compile the dependent png images as well.

Posted: Sat Jan 14, 2006 3:15 am
by kornerr
And how to create xrc? How to compile it?

Thanks.

Posted: Sat Jan 14, 2006 1:04 pm
by ssigala
kornerr wrote: But when I run app, I see the warning:

Code: Select all

No image handler for type 15 defined.
and there's no image at the button.
Maybe your wxWidgets library has no PNG support compiled in?