如何将TKinter PhotoImage保存为.GIF?
我可以只用Python和tkinter把一个tkinter的PhotoImage保存为.gif(或者其他任何图片格式)吗?
2 个回答
2
看起来这个方法 write
可以用来把 PhotoImage 保存到一个文件里。
>>> help(Tkinter.PhotoImage.write)
Help on method write in module Tkinter:
write(self, filename, format=None, from_coords=None) unbound Tkinter.PhotoImage method
Write image to file FILENAME in FORMAT starting from
position FROM_COORDS.
使用的例子可能是这样的:
my_photo_image.write("output.gif")
3
假设 photo
是一个用来存放你图片的变量,你只需要这样写:
photo.write('some_name.gif', format='gif')
虽然没有明确说明,但它支持查看 PGM、PPM、GIF 和 PNG 格式,所以我猜它也可以保存成这些格式。