我正在使用一个返回 Gtk.Image 对象的外部 api。我正在尝试将 Gtk.Image 写入文件。为了说明问题,我创建了以下代码:
from gi.repository import Gtk
import cStringIO
i = Gtk.Image()
i.set_from_file('/home/leon/Pictures/msn/ikea.jpg')
p = i.get_pixbuf()
f = open('/tmp/test.png', 'wb+')
def write(*args, **kwargs):
f.write(args[0])
return True
# ubuntu 11.10 doesn't have pixbuf.save_to_callback so instead use save_to_callbackv
p.save_to_callbackv(write, None, "png", [], [])
f.close()
该文件被写入磁盘但已损坏。为什么会损坏?