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

sangkexian 2009-08-21 02:55:06
如何用Python显示gif动态格式的图片
本人初学Python ,请各位高手写的详细点儿
...全文
3629 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qinguan0619 2009-08-30
  • 打赏
  • 举报
回复
我发现用一般的图片查看器不支持动态效果显示,但调用浏览器查看图片就会出现动态效果。。。

import os
os.system(r"start C:\Users\qinguan\Desktop\rain.gif")

C:\Users\qinguan\Desktop\rain.gif为gif动态图片
wangyaosuper 2009-08-29
  • 打赏
  • 举报
回复
用wxpython也可以

import wx
from wx.animate import GIFAnimationCtrl

from Main import opj

GIFNames = [
"bitmaps/ani-bttrfly.gif",
"bitmaps/ani-avtr.gif",
"bitmaps/ani-phone.gif",
# "bitmaps/ani-walker.gif",
"bitmaps/ani-man.gif",
"bitmaps/ani-bookworm.gif",
"bitmaps/ani-hooked.gif",
]

#----------------------------------------------------------------------

class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)

sizer = wx.FlexGridSizer(2,3,5,5)
for name in GIFNames:
ani = GIFAnimationCtrl(self, -1, opj(name))
ani.GetPlayer().UseBackgroundColour(True)
ani.Play()
sizer.Add(ani, 0, wx.ALL, 10)

border = wx.BoxSizer()
border.Add(sizer, 1, wx.EXPAND|wx.ALL, 20)
self.SetSizer(border)


#----------------------------------------------------------------------

def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win

#----------------------------------------------------------------------



overview = """<html><body>
<h2><center>wx.animate.GIFAnimationCtrl</center></h2>

wx.animate.GIFAnimationCtrl is like a wx.StaticBitmap but is able to
display an animation by extracing frames from a multi-images GIF file.

</body></html>
"""



if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])


cppfaq 2009-08-26
  • 打赏
  • 举报
回复
开来只有用pyglet了
DarkChampion 2009-08-21
  • 打赏
  • 举报
回复 1
可以使用pyglet模块来显示

# load and show an animated gif file using module pyglet
# download module pyglet from: http://www.pyglet.org/download.html
# the animated dinosaur-07.gif file is in the public domain
# download from http://www.gifanimations.com
# tested with Python2.5 and pyglet1.1a2 by vegaseat 22apr2008

import pyglet

# pick an animated gif file you have in the working directory
ag_file = "0022.gif"
animation = pyglet.resource.animation(ag_file)
sprite = pyglet.sprite.Sprite(animation)

# create a window and set it to the image size
win = pyglet.window.Window(width=sprite.width, height=sprite.height)

# set window background color = r, g, b, alpha
# each value goes from 0.0 to 1.0
green = 0, 1, 0, 1
pyglet.gl.glClearColor(*green)

@win.event
def on_draw():
win.clear()
sprite.draw()

pyglet.app.run()
fibbery 2009-08-21
  • 打赏
  • 举报
回复
http://www.diybl.com/course/1_web/webjs/200824/99396.html

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧