有没有办法使用wxPython的GIFAnimationCtrl(需要文件名,而不是文件)和img2py生成的图像?
答案 0 :(得分:1)
我不知道PyEmbeddedImage和img2py.py,但这是我发现将动画嵌入python源代码的方法。
gif_img_base64 = (
"R0lGODlhEAAQAPQAAP///wAAAPDw8IqKiuDg4EZGRnp6egAAAFhYWCQkJKysrL"
"6+vhQUFJycnAQEBDY2NmhoaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
...
"PAqFgYy02xkSaLEMV34tELyRYNEsCQyHlvWkGCzsPgMCEAY7Cg04Uk48LAsDhR"
"A8MVQPEF0GAgqYYwSRlycNcWskCkApIyEAOwAAAAAAAAAAAA=="
)
a = wx.animate.GIFAnimationCtrl(self, -1, '') # The control
a2 = wx.animate.Animation() # The data
data = base64.b64decode(gif_img_base64)
a2.Load(cStringIO.StringIO(data))
a.SetAnimation(a2) # Bind the data and the control
a.GetPlayer().UseBackgroundColour(True)
a.Play()
变量gif_img_base64是带动画的GIF文件的base64编码内容。一个帮助程序来创建代码:
import sys, base64
data = sys.stdin.read()
s = base64.b64encode(data)
print 'gif_img_base64 = ('
while s:
print ' "' + s[:62] + '"'
s = s[62:]
print ' )'