[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame.image.frombuffer problems



On Fri, 2005-12-30 at 09:56 -0600, Trevor Fancher wrote:
> I've found a thread[1] that turns into a discussion about more or less
> exactly what I want to do, but it appears no one ever actually got what
> I am trying to do to work.  I couldn't find any way to write a "raw"
> PNG (if that is even what it is called) out with pycairo, though I am
> sure it is possible using cairo's C api.
> 
> I may hack around with the pycairo code a bit to see if I can add the
> functionality myself.

It isn't really a "raw PNG" file, the string is just the raw pixel
representation of the image.

I'm confident in the pygame code to handle this. This is the way images
are currently transferred between python programs like pygame, pyopengl,
pil, and pymedia. The pygame tostring and fromstring are currently
working with these other packages.

I'm browsing the pycairo source now. The function you want is already
there, it is a method called "to_rgba" on the ImageSurface objects. This
returns the string buffer object you can use with
pygame.image.frombuffer() or pygame.image.fromstring()

You may also consider the ImageSurface.create_for_data() classmethod
which should allow you to get into cairo from pygame's fromstring()
function.