[wxPython-users] using wxImage in C++ python extension

Robin Dunn robin at alldunn.com
Mon Aug 14 10:20:54 PDT 2006


Andrew Murray wrote:
> I've writen (and built) a wee C++ extension that allows me to load and
> manipulate some custom image types from Python.  
> 
> To make the class offered by my extension more useful in a wxPython image
> display app that I use, I'd now like to add a method that returns a reference to
> a instance of a wxImage containing a representation of the member image data.
> 
> My problem lies in determining the simplest/most elegant way to add the ability
> to use a wxImage type in my extension.  
> 
> I know that I require a header file to include in my C++ (to define wxImage) and
> a library file (that includes a wxImage constructor) to link against.  My
> initial investigations pointed to use of the wxWidgets wx/image.h header.  Alas
> my attempts to use this seem to indicate that I'm going to need to make 
> wxWidgets from source on my machine.  I'm doing this in the background - but it
> seems like overkill.  
> 
> Am I barking up the wrong tree?  Is there header supplied in the wxPython source
> distribution I can use and a pre-compiled library in the wxPython binary
> distribution that I can link to instead?  
> 
> Or do compiler/name-mangling difference mean that I'm really better to build
> everything myself?
> 
> thanks in advance for any tips...
> 
> Andrew ;)
> 
> ps. I'm using MING which I know may complicate things as wxPython seems to be
> build using MSVC

Correct.  Mingw32 uses a different name-mangling scheme than MSVC, so 
yes, you'll have to build everything yourself if you want to use wxImage 
from C++.

OTOH, if you don't mind an extra data copy then your extension could 
just provide the image data as a string or RGB bytes and then you can 
create the wx.Image from Python using that string and the 
wx.ImageFromData constructor.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list