[PyQt] Re: QPixmap / QImage from numpy or string

Matthew Smith melkor at orangepalantir.org
Sun Jun 28 17:34:15 BST 2009


When I do this I use an RGB image becuase each line of your image needs
to be a multiple of 32bits or something like that, it says it in the
QImage documention.

Also I need to keep a reference to my original array.


total = numpy.zeros((h,w,4),numpy.uint8)

#code to fill total with image data

nimage = QtGui.QImage(total.data,w,h,QtGui.QImage.Format_RGB32)
nimage.ndarray = total

I got this base on some code from the PyQwt mailing list. Ill attach it.

mbs

> hi,
> 
> I am trying to create a QImage from a numpy array directly. this is
> not supported yet, right?
> has anybody tried to load a numpy array via a string into a QImage,
> like

> a = numpy.zeros((100,50))
> image = QImage(a.tostring(), a.shape[0], a.shape.[1], a.shape[0],
> OImage.Format_Mono)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: qimage2ndarray.py
Type: text/x-python
Size: 2580 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090628/7ab121ab/qimage2ndarray.py


More information about the PyQt mailing list