Page 1 of 1

Most recent wxInclude release ?

Posted: Sun Apr 21, 2013 1:06 pm
by eranon
Hello. I'm managing to embed some PNG images in my project's code (I prefer a cross-platform way rather than going with resource). So, and because I would like to keep these images in a single header file, I use wxInclude ; the one downloaded following the link from http://wiki.wxwidgets.org/Embedding_PNG_Images.

Well, however, the macros and inline functions wxInclude generates seems to be wrong and don't compile (currently under Windows, wxWidgets 2.9.4 and GCC) ; call doesn't match wxImage ctor prototypes (don't remember the exact error, but something like a long integer which should be a wxString).

So, I've commented the functions and macros produced by wxInclude and written the ones advised in the wiki :

Code: Select all

#define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name ## _png, sizeof(name ## _png))

 inline wxBitmap _wxGetBitmapFromMemory(const unsigned char *data, int length)
 {
   wxMemoryInputStream is(data, length);
   return wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1);
 }
De facto, my questions are :

Is there an up-to-date wxInclude somewhere ? The one I talk here seems to be compiled on 2007.
Or, is there an easy way to produce several image declarations in a single header (.h) from bin2c or png2wx ?

Re: Most recent wxInclude release ?

Posted: Sun Apr 21, 2013 4:24 pm
by eranif
Have you considered using wxrc for this purpose?

1. Create a XRC file with the following content (call it resources.xrc)

Code: Select all

<resource>
   <object class="wxBitmap" name="test">C:\src\images\test.png</object>
</resource>
2. Convert the XRC file into C++ file, by typing from the command line the following:

Code: Select all

wxrc /c /v /o resources.cpp resources.xrc
this line will produce file name resources.cpp - add it to your project

3. In your code, add this line somewhere in the initialization of your application (App::OnInit() maybe):

Code: Select all

// this function is located inside the resources.cpp file
extern void InitXmlResource(); 

// initialize the images from the xml resource file
InitXmlResource();

4. Now you are ready to use the images in your code:

Code: Select all

//load image from the resources manager
wxBitmap bmp = wxXmlResource::Get()->LoadBitmap(wxT("test");
Eran

Re: Most recent wxInclude release ?

Posted: Mon Apr 22, 2013 11:31 am
by eranon
Yes, it's also a way and thanks for this detailled tuto Eranif, but it's one step more than going from PNG to C array through bin2c or wxInclude directly. But maybe there're some considerations I've missed... Let me know...

At this stage, all sounds right with wxInclude. I've simply used its "--noheader --wxnone" options to do it only produce the data arrays and nothing more. Also, I've moved the required macro and inline functions in a global.h I already have for this project.