如何将Gtk.Image转换为base64
我有一个Gtk.Image对象,我想把它的数据转换成一个base64编码的字符串(为了在imgur上使用)。我该怎么做呢?
1 个回答
1
需要通过一个叫 gdk.pixbuf 的东西来运行,但这看起来是最简单的方法:
import cStringIO
import base64
pixBuf = gtkImage.get_pixbuf()
fH = cStringIO.StringIO()
pixBuf.save_to_callback(fH.write, "png")
encodedBuffer = base64.b64encode(fH.getvalue()) #base64 encoded png