[cairo] Pycairo + PNG Output

Vladimir Vukicevic vladimirv at gmail.com
Wed Oct 12 00:34:16 PDT 2005


On 10/11/05, James Mills <prologic at shortcircuit.net.au> wrote:
> On Wed, Oct 12, 2005 at 11:43:34AM +0800, Steve Chaplin wrote:
> > I dropped the 'stream' from pycairo since it seems to be a C++/Java
> > term, whereas the Python documentation talks about 'file objects' and
> > 'file-like objects'.
> >
> > pycairo release 1.0.2 has
> >    surface.write_to_png(f)
> > where 'f' can be a filename or a file object.
> >
> > I've just updated cvs so that 'f' can now be a filename, a file object
> > or a file-like object that has a "write" method (like StringIO or
> > cStringIO). It can be used like this:
>
> Thank you. I think this is what we need :)
>
> So I presume now with this change we can do:
>
> import cairo
> import pygame
>
> surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
> import StringIO
> buffer = StringIO.StringIO()
> image = pygame.image.frombuffer(buffer)

I'm assuming there's some kind of write_to_png(buffer) call right
before the pygame.image.frombuffer?

Ideally, you really want pycairo to allocate its own buffer for the
cairo image surface, and let you access it, to pass it to pygame
directly as a 32-bbp ARGB image.  Otherwise, you waste lots of CPU
doing png encoding/decoding for no reason, especially if you do this
often...

    - Vlad


More information about the cairo mailing list