Displaying an embedded image on PyQt?

前端 未结 1 865
遥遥无期
遥遥无期 2021-01-24 14:32

Let\'s say I have the base-64 code of an image in my script like so:

EmbeddedCode = \"\"\"INSERTCODEHERE.....
.....EXAMPLEEXAMPLE\"\"\"

If I co

1条回答
  •  北海茫月
    2021-01-24 15:08

    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_()
    

    0 讨论(0)
提交回复
热议问题