load gif into QMovie object from data (no file)

血红的双手。 提交于 2020-01-21 20:45:46

问题


I have read through many questions, most of which not on this site, and they all mention QMovie must be called with a file name, like this

anim = QtGui.QMovie("Filename.gif")

#or

self.movie = QMovie(filename, QByteArray(), self) #self is implied a class/super

but I was wondering if there was any way to load this from data directly, similar to QPixMap:

Img = QtGui.QPixMap()
Img.loadFromData("\x00\x5f\xaa\x3a... ...\xff")

#or
data = open("file.gif", "rb").read() #So you get what I mean
Img.loadFromData(data)

Thanks!


回答1:


The QMovie constructor can take a QIODevice as first argument, so the gif data can be loaded via a QBuffer:

a = QtCore.QByteArray(data)
b = QtCore.QBuffer(a)
b.open(QtCore.QIODevice.ReadOnly)
m = QtGui.QMovie(b, 'GIF')


来源:https://stackoverflow.com/questions/27214178/load-gif-into-qmovie-object-from-data-no-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!