加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

如何用Python显示gif动态格式的图片

(2009-09-21 11:53:30)
标签:

杂谈

我所知道的两种方法: 一、用pyglet模块 #loadandshowananimatedgiffileusingmodulepyglet #downloadmodulepygletfrom:http://www.pyglet.org/download.html #theanimateddinosaur-07.giffileisinthepublicdomain #downloadfromhttp://www.gif

我所知道的两种方法:

一、用pyglet模块

  1. load and show an animated gif file using module pyglet  
  2. download module pyglet from: http://www.pyglet.org/download.html  
  3. the animated dinosaur-07.gif file is in the public domain  
  4. download from http://www.gifanimations.com  
  5. tested with Python2.5 and pyglet1.1a2 by vegaseat 22apr2008  
  6.  
  7. import pyglet  
  8.  
  9. pick an animated gif file you have in the working directory  
  10. ag_file "0022.gif" 
  11. animation pyglet.resource.animation(ag_file)  
  12. sprite pyglet.sprite.Sprite(animation)  
  13.  
  14. create window and set it to the image size  
  15. win pyglet.window.Window(width=sprite.width, height=sprite.height)  
  16.  
  17. set window background color r, g, b, alpha  
  18. each value goes from 0.0 to 1.0  
  19. green 0101 
  20. pyglet.gl.glClearColor(*green)  
  21.  
  22. @win.event  
  23. def on_draw():  
  24.     win.clear()  
  25.     sprite.draw()  
  26.  
  27. pyglet.app.run() 


二、用wxPython

 

  1. import wx  
  2. from wx.animate import GIFAnimationCtrl  
  3.  
  4. from Main import opj  
  5.  
  6. GIFNames [  
  7.     "bitmaps/ani-bttrfly.gif",  
  8.     "bitmaps/ani-avtr.gif",  
  9.     "bitmaps/ani-phone.gif",  
  10.    "bitmaps/ani-walker.gif",  
  11.     "bitmaps/ani-man.gif",  
  12.     "bitmaps/ani-bookworm.gif",  
  13.     "bitmaps/ani-hooked.gif",  
  14.     ]  
  15.  
  16. #----------------------------------------------------------------------  
  17.  
  18. class TestPanel(wx.Panel):  
  19.     def __init__(selfparent, log):  
  20.         self.log log  
  21.         wx.Panel.__init__(selfparent, -1)  
  22.  
  23.         sizer wx.FlexGridSizer(2,3,5,5)  
  24.         for name in GIFNames:  
  25.             ani GIFAnimationCtrl(self-1opj(name))  
  26.             ani.GetPlayer().UseBackgroundColour(True)  
  27.             ani.Play()  
  28.             sizer.Add(ani, 0wx.ALL, 10)  
  29.  
  30.         border wx.BoxSizer()  
  31.         border.Add(sizer, 1wx.EXPAND|wx.ALL, 20)  
  32.         self.SetSizer(border)  
  33.           
  34.  
  35. #----------------------------------------------------------------------  
  36.  
  37. def runTest(frame, nb, log):  
  38.     win TestPanel(nb, log)  
  39.     return win  
  40.  
  41. #----------------------------------------------------------------------  
  42.  
  43.  
  44.  
  45. overview """<html><body>  
  46. <h2><center>wx.animate.GIFAnimationCtrl</center></h2>  
  47.  
  48. wx.animate.GIFAnimationCtrl is like wx.StaticBitmap but is able to  
  49. display an animation by extracing frames from multi-images GIF file.  
  50.  
  51. </body></html>  
  52. """ 
  53.  
  54.  
  55.  
  56. if __name__ == '__main__':  
  57.     import sys,os  
  58.     import run  
  59.     run.main([''os.path.basename(sys.argv[0])] sys.argv[1:])  

有其他方法,请大家留言

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有