save gtk.DrawingArea to file

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 10:54:11

问题


I want to save gtk.DrawingArea() object contents to jpeg file using PIL. Particularly I want add to this script possibility to make photo. I found how to save image to jpeg. All I need - get pixbuf object from gtk.DrawingArea() object. How can I do this?


回答1:


If you're not married to the idea of using gstreamer, you can use OpenCV instead. This post gives a great example using pygame.

However, you can get the pixbuf this way (and you don't even need PIL):

def get_picture(self, event, data):
    drawable = self.movie_window.window
    colormap = drawable.get_colormap()
    pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8, *drawable.get_size())
    pixbuf = pixbuf.get_from_drawable(drawable, colormap, 0,0,0,0, *drawable.get_size())
    pixbuf.save(r'somefile.png', 'png')
    pixbuf.save(r'somefile.jpeg', 'jpeg')

and then just create a button and bind the command to get_picture.

Of course, if I were writing this program I would actually grab the image to an Image in the first place and then draw it on the gtk.DrawingArea - that would allow you to do all sorts of fun things.



来源:https://stackoverflow.com/questions/3254499/save-gtk-drawingarea-to-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!