[cairo] pycairo and PIL

James Evans milamber at clark-evans.com
Thu Sep 22 05:39:41 PDT 2005

> Are you saying that to get wxPython to work with pycairo you should use
> PIL? I don't know why PIL would be needed and think it would be better
> to connect wxPython directly to pycairo, using a method similar to the
> way pygtk connects to pycairo. But I don't know the specific details as
> I don't use wxPython.

I guess I didn't explain that one very well. I'm not thinking that
wxPython needs PIL to use cairo, but that the same methods that are useful
for PIL can be useful for wxPython.

> Cairo and pycairo being low-level graphics libraries that higher-level
> libraries can require and build upon. So I think that PIL (or any other
> module) could check if pycairo is installed and optionally build
> functions to interface to pycairo, rather than the other way round.
> So in this case PIL could provide a "get_data(surface)" or "Image.from
> cairosurface()" function.

This was exactly my problem. How does PIL get access to the data in a
cairo surface? The only exposed interface is by giving a numpy array to
cairo to use as a surface. Numpy is a large addition that in my
understanding (I've not used it extensively) suffers from performance
problems. What I was trying to do was to provide a python program direct
access to the data contained in the cairo surface. If pycairo doesn't
expose an API for accessing this, how is the python program going to get
at it?

I've only used cairo for a week or so, so it is very possible I missed
something here, but I didn't see any way to access the surface's data
(once again, excepting numpy). Is there a better way to get the data?

I know that undoing the premuliplication isn't the best way to pass the
data back, it just suits what I'm doing with it at this time. I'd think it
should be an option.


james evans

More information about the cairo mailing list