开发者

save gtk.DrawingArea to file

开发者 https://www.devze.com 2023-01-07 15:26 出处:网络
I want to save gtk.DrawingArea() object contents to jpeg file using PIL. Particularly I want add to this scriptpossibility to make photo. I found how to save image to jpeg. All I need - get pixbuf obj

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 c开发者_如何学Pythonan I do this?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消