[PyQt] Odd QImage behavior

Matt Smith melkor at orangepalantir.org
Thu Jan 29 13:41:59 GMT 2009


I made a mistake about what works and what doesn't.  If I use

nimage = QtGui.QImage(total.data,w,h,QtGui.QImage.Format_Indexed8)
nimage.setColorTable(COLORTABLE)

Then there is strange wrapping that occurs if the image is not the correct size
If I use:

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

Then it works fine, of course for both of those examples 'total' has a different shape. 

>Maybe there's an issue with padding/alignment in the data - I'm
>guessing that your numpy array has a compatible type. If your QImage is
>created using one of the C++ constructors that accepts char* or uchar*
>I can well imagine that this could be a problem.

I think that is the problem for two reasons.  First it depends on the
size of the array, and Second the .ndarray part is left off of first
example, and doesn't change anything when I include it.  

> Having said that, you would have thought that it wouldn't have a problem
> with raw bytes. Maybe look at the size of the data obtained from the array
> and see if it equals what you would expect.

I have checked the data by comparing sizes.  Also I implement a line
detection algorithm and the lines are drawn according to the correct
shape, while the data is displayed warped.

thanks
mbs



More information about the PyQt mailing list