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

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

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

Post by kornerr » Wed Jan 11, 2006 4:16 pm

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.
Open Source all the way, baby ;)
OpenGameStudio
Image

ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

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

Post by ssigala » Wed Jan 11, 2006 4:42 pm

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
Sandro Sigala - Kynosoft, Brescia

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Thu Jan 12, 2006 6:20 am

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)
Open Source all the way, baby ;)
OpenGameStudio
Image

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Thu Jan 12, 2006 7:49 am

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.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Thu Jan 12, 2006 1:07 pm

So there's no way to embed PNG into my executable like XPM :(
Open Source all the way, baby ;)
OpenGameStudio
Image

ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala » Thu Jan 12, 2006 2:12 pm

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);
Sandro Sigala - Kynosoft, Brescia

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Thu Jan 12, 2006 4:25 pm

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)
Open Source all the way, baby ;)
OpenGameStudio
Image

travfar
Earned some good credits
Earned some good credits
Posts: 132
Joined: Mon Apr 04, 2005 12:54 am
Location: California
Contact:

Post by travfar » Sat Jan 14, 2006 12:14 am

how about xrc, compile the xrc file into a cpp file and wxrc will compile the dependent png images as well.
I see said the blind man to the deaf girl who was mute.

Visit my project at: http://vwp.sourceforge.net

wx version:2.6.2 and 2.6.3 on linux
OS's:Windows XP, Gentoo is the best!!!!!!
compiler:Codeblocks(MingW32) and gcc on linux

kornerr
Experienced Solver
Experienced Solver
Posts: 66
Joined: Wed Oct 12, 2005 2:43 pm
Location: Russia
Contact:

Post by kornerr » Sat Jan 14, 2006 3:15 am

And how to create xrc? How to compile it?

Thanks.
Open Source all the way, baby ;)
OpenGameStudio
Image

ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala » Sat Jan 14, 2006 1:04 pm

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?
Sandro Sigala - Kynosoft, Brescia

Post Reply