一种选择是仅使用PIL库。
>>> import numpy as np>>> import Image>>> im = Image.fromarray(np.random.randint(0,256,size=(100,100,3)).astype(np.uint8))>>> im.show()
您可以在http://www.pyside.org/docs/pyside/PySide/QtGui/QImage.html上查看QPixmap构造函数。
看起来您应该能够直接在构造函数中使用numpy数组:
PySide.QtGui.QImage类(数据,宽度,高度,格式)
其中format参数是以下参数之一:http
:
//www.pyside.org/docs/pyside/PySide/QtGui/QImage.html#PySide.QtGui.PySide.QtGui.QImage.Format。
因此,例如,您可以执行以下操作:
>>> a = np.random.randint(0,256,size=(100,100,3)).astype(np.uint32)>>> b = (255 << 24 | a[:,:,0] << 16 | a[:,:,1] << 8 | a[:,:,2]).flatten() # pack RGB values>>> im = PySide.QtGui.QImage(b, 100, 100, PySide.QtGui.QImage.Format_RGB32)
我没有安装PySide,所以我没有对此进行测试。它可能无法按原样工作,但可能会引导您朝正确的方向发展。



