我遇到了一些问题,可以使用一些帮助。 我这里有一个显示像素图的小pyqt应用程序。
import sys
import qtcompress
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def window():
str_image = 'AAASDHicnVdlUBSO076DOySlUzqkuxuU7pRG8hAE6QY5uhvkaCXlSEGk4TyPUvBoCQlJT+CkO/7+Pr/f3mfm2Zjd2f2wszuzyUYGmiSEDIQAAIBEW0vN5J9W+Y/4eP8k3N135Z8C+T/RNsP/hwh8l6R/PoGPlpU/AEBE+R+BgKISun85D9zNLAMs9fXknL29hBxdvJ1chUK8fABAgLmZhqAM4P9GXkTvF4+/qtegGj4PJUQtfzRxvGj5zKoX8LL2HPJLSsdk2UW2jN6TyoFnbX60PnBS8w9/AN5NNEmGwGmQKZOLzaHszv296JfCQ08KW28/PXvL6rEF9u9Df1aj7qr5RJnqVxPEnd8YzovdXdm3JJ4/Zxm9Jjp8H8ZkD34UlbvNW9/Sqp3bcCLtTG2q5NZ/YZOQDZ/hmv1meStA+XV6z6DwIIb36fJkkrtNyi5me6JNI7ac6psIkwtxFsa9Zj/1B8LoUwGDfTL67dvsKOVb11TK1aE/rXA/lnenYY3NXqW0RGznCi6WI60Sxu/yva3ipa2fvfbQC1IyfZbD/r0e5pZyk7ETYZ5ufqrjbrfkW33JnJcfpqhRekDl5ZOht6zipta2MNwqsW/+Znb85emH1oiIb/TdblzPqeOWe1sbrmbc1EdXuJ9Taysq57G+aTHT0vnlerbypH+TWrjgZqzzHNNW2bzO8+fH1zEr+iWUm4vY9AgyVogsd8+QMIHfXsGvLE6/YHn/lWGhnosFyem7oy8dMpURdnd0b02Ny1mKU4J5PjZBiCWmQyWIF7KfGorbropYP9bfSh7WC1AepO5Hbb0/m0mclgnrGdkyCt0TLb7ssLL6lday5M6DE8Zouhpgt945Nue5rrHIw0A2zhHwduENZSGHswoHBzw9c4tpl5ebf0GH/YdA5NfkllXpJO+2kbJMAZs2AYufvaO2JKT68PSGrmTFR8Uum3sqgm0Pf3ew08hTGlhL+gmYITT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E9BmcsTeMmwmmBb2VFOFpz+uK9YHt/mwdgus82ATxThARNVRtZn+Jw8pmhvqq607ZTavJMOE0jOfQeZMJmfidrKQpOeNAhxdaXR0NBgCzIARQBk8PZo3JG653UbIwsPs2oGZuyze9vV/Icosou4QnsI7LCFhA0RNb0N9PGrDBEsMmwXg80RW/U/JG+rAYD5+fmk/Nn8DlBZ8VTP+TDiWVpdYJXY08caryLomBzzZ+oSNFg+vJgIWWHhVDMI3TkTwemk/DzE2qvi82StsbYszGMJKQwGIIauhj52d7eCj+zWghGViF9Xm4zXJm1yi8+YPTa6v1M7f8MBt2KCGQYEZD0SuZHhk4oGFF8GmyNvd6U5FX6iNEZPT9Mt7az6tBazThIQtNzrqrzy6vXw9jnSU8uswT43Mm/W/CInznZkIgPuHfRAfC0csYuQX73ZXl1tOfDJtXH9IT2He3G7uLgYBbiv99HJqlRj1M53ZrCQEqJqPV780G1bv4XvcHDEIBc/0euMNWMVJh3JFPlUFrpdWLzIH/EtKLW5sTEZjjVpN5eMnOfcp/nx+kHICqPiKqg0OJ3U3T9gUc3Ly6aPT4oulqTW/JRaXN4dsgsJwiy4lfdhBlePVokYFUKMZmb0vDLhSm89zotHuc291HeDLvFiMFAaVS/YPQSRcBIOnP0RQGcv2S74aMYw4h7136vw4K0ytu/c3nj2LJW8PbMYswzvhkPC9feDxJerb4U1xub0T9OKbv2MruNJPrnC74SVLz73tE4EU0PvSYfD7zRN/+K2TBPNYzYiAUFhQPnIG5axlCmO0mvWRsA/aKsbqDU9cYj5Hz3VwP4='
app = QApplication(sys.argv)
win = QWidget()
l1 = QLabel()
image = qtcompress.decode_thumbnail(str_image)
l1.setPixmap(QPixmap.fromImage(image))
vbox = QVBoxLayout()
vbox.addWidget(l1)
win.setLayout(vbox)
win.setWindowTitle("QPixmap Demo")
win.show()
sys.exit(app.exec_())
if __name__ == '__main__':
window()
这是decode_thumbnail函数
def decode_thumbnail(str_image):
bytearray = QtCore.QByteArray.fromBase64(str_image)
bytearray = QtCore.qUncompress(bytearray)
image = QtGui.QImage()
image.fromData(bytearray, 'PNG')
我经常环顾四周,似乎找不到任何人从base64解压缩字符串然后使用qUncompress的例子。 Python不是我的强项,所以如果这是一个简单的问题我会道歉。
答案 0 :(得分:0)
问题出在您的decode_thumbnail
功能中。它没有返回任何东西。
从
更改最后一行 image.fromData(bytearray, 'PNG')
到
return image.fromData(bytearray, 'PNG')
或者,由于QImage.fromData
是静态方法,因此您不需要image
对象,因此您只需编写
def decode_thumbnail(str_image):
bytearray = QByteArray.fromBase64(str_image)
bytearray = qUncompress(bytearray)
return QImage.fromData(bytearray, 'PNG')