假设我的脚本中有图像的base-64代码,如下所示:
EmbeddedCode = """INSERTCODEHERE.....
.....EXAMPLEEXAMPLE"""
如果我能像这样解码它:
EmbeddedCode.decode('base64')
然后如何在这样的PyQt4 gui中显示它?:
pic = QtGui.QLabel(self)
pic.setGeometry(0, 0, 512, 512)
pic.setPixmap(QtGui.QPixmap(IMAGE PATH GOES HERE))
最好是不必使用open('image.jpg','w')
,如果问不多的话。
注意:我正在使用嵌入式图像,因为我确实希望没有'resources'文件夹。我需要处理的垃圾越少越好。
使用QPixmap的loadFromData方法:
from PyQt4 import Qt,QtGui,QtCore
import base64
# "b64_data" is a variable containing your base64 encoded jpeg
app = QtGui.QApplication([])
w = QtGui.QWidget()
pic = QtGui.QLabel(w)
pm = QtGui.QPixmap()
pm.loadFromData(base64.b64decode(b64_data))
pic.setPixmap(pm)
w.show()
app.exec_()
如果我要嵌入.dcm(DICOM)图像该怎么办?