问题
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