[pygtk] Help with pygtk save_to_callback
Tim Evans
t.evans at aranz.com
Tue Apr 18 08:16:06 WST 2006
Michael Urban wrote:
> Hi all,
>
> I need some help using the pixbuf safe_to_callback method. Basically,
> what I need to do is take a pixbuf, and save it to an in memory
> buffer in jpg format that I can dump to a db. I'm running into two
> main problems:
>
> 1: The callback seems to get called multiple times. So calling
> pixbuf.save_to_callback apparently doesn't pass all of the buffer in
> one call, but make several calls to the callback.
The callback replaces fwrite to a file, it may be called many times in
the course of saving a file.
> 2: Simply trying to append onto the end of a buffer that you build
> incrementally does not work. It causes a gobject.GError write
> function failed.
I would need to see your code to understand why this isn't working.
> Can anyone give me a simple example of how I would write a callback
> function for pixbuf.save_to_callback that would build an in memory
> buffer that stores the image in the given file type?
Untested, but maybe something like this, where 'p' is a pixbuf:
import cStringIO as StringIO
io = StringIO.StringIO()
p.save_to_callback(io.write, 'png')
buffer = io.getvalue()
--
Tim Evans
Applied Research Associates NZ
http://www.aranz.co.nz/
More information about the pygtk
mailing list