2015-03-15 5 views

risposta

10

dal documentation,

The get_pixbuf() method gets the gtk.gdk.Pixbuf being displayed by the gtk.Image . The return value may be None if no image data is set. If the storage type of the image is not either gtk.IMAGE_EMPTY or gtk.IMAGE_PIXBUF the ValueError exception will be raised.

(sottolineatura mia)

Come avete bisogno di un png file di , è possibile seguire le istruzioni da 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') 

Questo creerà una pixbuf dal pixmap che è disp.pixmap. Questo può essere successivamente salvato usando pixbuf.save

3

In attesa della risposta in realtà ho trovato la soluzione

pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height) 
pixbf = pixbuf.get_from_drawable(disp.pixmap, disp.pixmap.get_colormap(), 0, 0, 0, 0, width, height) 
pixbf.save('path.png') 

assumendo disp.pixmap è il tuo oggetto pixmap

4

In questi casi è utile leggere la documentazione da Gtk stesso, invece che da PyGtk, poiché sono più completi.

In questo caso le relative funzioni sono gtk_image_set_from_pixmap() e gtk_image_get_pixbuf():

Gets the GdkPixbuf being displayed by the GtkImage. The storage type of the image must be GTK_IMAGE_EMPTY or GTK_IMAGE_PIXBUF.

Il problema è che il widget GtkImage può contenere sia un GdkPixbuf, un GdkPixmap, un GdkImage ... ma non in grado di convertire tra di loro, cioè, puoi solo recuperare ciò che hai archiviato.

Si sta memorizzando una pixmap e cercando di ottenere un pixbuf, e questo non funzionerà. Ora, qual è la soluzione? Dipende da cosa stai cercando di fare esattamente. Probabilmente è sufficiente se lo converti in un pixbuf con gtk.pixbuf.get_from_drawable():

w,h = disp.pixmap.get_size() 
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, w, h) 
pb.get_from_drawable(disp.pixmap, disp.pixmap.get_colormap(), 
    0, 0, 0, 0, width, height) 
pb.save('path.png') 
Problemi correlati