[pygtk] Saving a gdk.Pixmap bitmap

John Finlay finlay at moeraki.com
Thu Jul 27 19:09:16 WST 2006


Joachim Breitner wrote:
> Hi,
>
> I have a gdk.pixmap that is a bitmap (depth 1), and I want to save it to
> disk. I tried to go by a Pixbuf, but that failed because it seemed to
> need a pixmap. I tried:
>    pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,800,600)
>    pixbuf.get_from_drawable( self.bitmap,None,0,0,0,0,-1,-1)
>    pixbuf.save(filename, "png", {})
> whereas self.bitmap was created by:
>    self.bitmap = gtk.gdk.Pixmap(None, 800, 600, 1)
>
> If I pass gtk.gdk.colormap_get_system() as the Colormap parameter, I do
> get a file, but it is monochrome empty.
>
> Thanks for a pointer to how I can do that.
>
>   
You could try the following:

- create a pixmap and a pixbuf the same size as your bitmap
- create a GC and use the bitmap as the clip_mask
- draw a filled rectangle on the pixmap using the new gc
- get representation of the pixmap into the pixbuf using get_from_drawable
- save the pixbuf to a file using one of the writable formats on your 
system.

John


More information about the pygtk mailing list