Scale an image in GTK

后端 未结 6 1650
太阳男子
太阳男子 2020-12-16 13:19

In GTK, how can I scale an image? Right now I load images with PIL and scale them beforehand, but is there a way to do it with GTK?

6条回答
  •  不思量自难忘°
    2020-12-16 14:00

    Load the image from a file using gtk.gdk.Pixbuf for that:

    import gtk
    pixbuf = gtk.gdk.pixbuf_new_from_file('/path/to/the/image.png')
    

    then scale it:

    pixbuf = pixbuf.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
    

    Then, if you want use it in a gtk.Image, crate the widget and set the image from the pixbuf.

    image = gtk.Image()
    image.set_from_pixbuf(pixbuf)
    

    Or maybe in a direct way:

    image = gtk.image_new_from_pixbuf(pixbuf)
    

提交回复
热议问题