Issue
Let's say I have the base-64 code of an image in my script like so:
EmbeddedCode = """INSERTCODEHERE.....
.....EXAMPLEEXAMPLE"""
If I could decode it like this:
EmbeddedCode.decode('base64')
Then how can I display it in a PyQt4 gui like this?:
pic = QtGui.QLabel(self)
pic.setGeometry(0, 0, 512, 512)
pic.setPixmap(QtGui.QPixmap(IMAGE PATH GOES HERE))
Preferably without having to use open('image.jpg','w')
, if it's not to much to ask.
Note: I am using embedded images because I'd really rather not have a 'resources' folder. the less crap I have to deal with, the better.
Solution
Use the loadFromData method of QPixmap:
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_()
Answered By - mguijarr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.