1

我有一个 Gtk.Image 对象,我想将它的数据转换为 base64 编码的字符串(与imgur一起使用)。我将如何实现这一目标?

4

1 回答 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
于 2012-02-05T15:36:44.473 回答