本文介绍了从数据(没有文件)将gif加载到QMovie对象中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经阅读了许多问题,大多数问题不在本网站上,而且他们都提到必须使用这样的文件名来调用QMovie
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
但是我想知道是否有任何方法可以像QPixMap一样直接从数据中加载它:
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)
谢谢!
推荐答案
QMovie
构造函数可以将QIODevice
作为第一个参数,因此可以通过QBuffer
加载gif数据:
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')
这篇关于从数据(没有文件)将gif加载到QMovie对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!