THIS link describes a way to set a QPixmap without using QImage. How can I reproduce this in python?
what I have is a buffer, which represents an image.
what I need is to call something like
label.setPixmap(QPixmap.loadFromData(buffer))
to display the image. But before that, a format header has to be inserted, according to the link for a 300x300 grayscale image the header is something like "P6 300 300 255". I have no idea how to do that.
Here is the whole script:
import numpy as np
import cv2
import sys
from PySide.QtGui import QApplication,QLabel,QPixmap
if QApplication.instance() is not None:
a=QApplication.instance()
else:
a = QApplication(sys.argv)
lbl=QLabel()
header = bytearray(b"P6 20 20 255")
cvImg=np.zeros((20,20),dtype=np.uint8)
cv2.circle(cvImg,(9,9),9,49,-1)
buff=cvImg.data
ppm=header+buff
pixmap=QPixmap()
lbl.setPixmap(pixmap.loadFromData(ppm,40,format="PPM"))
sys.exit(a.exec_())
It says:
TypeError: 'PySide.QtGui.QPixmap.loadFromData' called with wrong argument types:
PySide.QtGui.QPixmap.loadFromData(bytearray, int, str)
Supported signatures:
PySide.QtGui.QPixmap.loadFromData(PySide.QtCore.QByteArray, str = None, PySide.QtCore.Qt.ImageConversionFlags = Qt.AutoColor)
PySide.QtGui.QPixmap.loadFromData(PySide.QtCore.uchar, unsigned int, str = None, PySide.QtCore.Qt.ImageConversionFlags = Qt.AutoColor)