How can I save a pixmap as a .png file?
I do this:
image = gtk.Image()
image.set_from_pixmap(disp.pixmap, disp.mask)
pixbf=image.get_pixbuf()
pixbf.save('path.png')
I get this error:
pixbf=image.get_pixbuf()
ValueError: image should be a GdkPixbuf or empty
From the documentation,
The
get_pixbuf()
method gets thegtk.gdk.Pixbuf
being displayed by thegtk.Image
. Thereturn
value may beNone
if no image data is set. If the storage type of the image is not eithergtk.IMAGE_EMPTY
orgtk.IMAGE_PIXBUF
the ValueError exception will be raised.
(Emphasis Mine)
As you need a png file, You can follow the instructions from here
pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,has_alpha=False, bits_per_sample=8, width=width, height=height)
pixbuf.get_from_drawable(disp.pixmap, disp.pixmap.get_colormap(), 0, 0, 0, 0, width, height)
pixbuf.save('path.png')
This will create a pixbuf
from your pixmap
which is disp.pixmap
. This can be later saved using pixbuf.save