PySide.QtGui.QImage到Base64

2024-10-01 05:01:07 发布

您现在位置:Python中文网/ 问答频道 /正文

为新手的问题道歉,但找不到解决方法。你知道PySide.QtGui.QImage转换base64映像还是将数据转换为字符串?在

我试过了

image_data = base64.b64encode (imageActual)

但我得到了这个错误

TypeError: must be string or buffer, not PySide.QtGui.QImage

谢谢


Tags: 数据方法字符串imagedata错误pysidebase64
2条回答

转换为base64:

    img = QtGui.QImage('image.png')
    ba = QtCore.QByteArray()
    buffer = QtCore.QBuffer(ba)
    buffer.open(QtCore.QIODevice.WriteOnly)
    img.save(buffer, 'PNG')
    base64_data = ba.toBase64().data()

从base64转换:

^{pr2}$

我可以用这个来解决我的问题:

image_64_decode = base64.decodestring(base64Data)
image = QtGui.QImage()
image.loadFromData(image_64_decode , 'PNG')

相关问题 更多 >