将gtk.DrawingArea保存到文件 [英] save gtk.DrawingArea to file

查看:158
本文介绍了将gtk.DrawingArea保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用PIL将gtk.DrawingArea()对象内容保存为jpeg文件。特别我想添加这个脚本制作照片的可能性。我发现如何将图像保存为jpeg 。我所需要的 - 从gtk.DrawingArea()对象获取pixbuf对象。如何才能做到这一点?

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?

推荐答案

如果您不想使用gstreamer,您可以改用OpenCV。 这篇文章使用pygame给出了一个很好的例子。

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

然而,你可以通过这种方式获得pixbuf(并且你甚至不需要PIL):

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

,然后创建一个按钮并将命令绑​​定到 get_picture

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

当然,如果我正在编写这个程序,我实际上会首先将图像抓到 Image 然后在 gtk.DrawingArea 上绘制它 - 这将允许您执行各种有趣的事情

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.

这篇关于将gtk.DrawingArea保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆