2015-03-15 14 views
10

मैं एक पंपमैप को .png फ़ाइल के रूप में कैसे सहेज सकता हूं?
मैं यह कर:एक पेंग फ़ाइल को एक पेंग फ़ाइल के रूप में सहेजने का प्रयास करते समय ValueError

image = gtk.Image() 
    image.set_from_pixmap(disp.pixmap, disp.mask) 
    pixbf=image.get_pixbuf() 
    pixbf.save('path.png') 

मैं इस त्रुटि मिलती है:

pixbf=image.get_pixbuf() 
    ValueError: image should be a GdkPixbuf or empty 

उत्तर

10

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.

(जोर मेरा)

आप एक png फ़ाइल की आवश्यकता के रूप में, आप से 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') 

निर्देशों का पालन कर सकते हैं यह आपके pixmap जो disp.pixmap है से एक pixbuf पैदा करेगा। इसे बाद में pixbuf.save

3

जबकि उत्तर के लिए इंतजार कर मैं वास्तव में समाधान

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') 

disp.pixmap संभालने पाया अपने पिक्समैप वस्तु है

4

इन मामलों में पीईजीटीके की बजाय जीटीके से दस्तावेज़ों को पढ़ने के लिए उपयोगी है, क्योंकि वे अधिक पूर्ण हैं।

इस मामले में प्रासंगिक कार्यों gtk_image_set_from_pixmap() और 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.

समस्या यह है कि GtkImage विजेट पकड़ सकता है दोनों एक GdkPixbuf, एक GdkPixmap, एक GdkImage ... लेकिन यह उन दोनों के बीच परिवर्तित नहीं कर सकते, यही है, आप केवल जो भी आपने संग्रहीत किया है उसे पुनर्प्राप्त कर सकते हैं।

आप एक पिक्समैप संग्रहित कर रहे हैं और एक पिक्सबफ प्राप्त करने की कोशिश कर रहे हैं, और यह काम नहीं करेगा। अब, समाधान क्या है? यह उस पर निर्भर करता है कि आप वास्तव में क्या करने की कोशिश कर रहे हैं। शायद यह पर्याप्त है यदि आप इसे 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') 
के साथ एक पिक्सबफ में कनवर्ट करें
संबंधित मुद्दे

 संबंधित मुद्दे