[PyQt] Re: numpy to QImage

Tony Willis Tony.Willis at nrc-cnrc.gc.ca
Sun Feb 24 16:10:02 GMT 2008


On Sun, 24 Feb 2008 pyqt-request at riverbankcomputing.com wrote:

>    1. QImage from Python buffer (Jeremy Sanders)

> From: Jeremy Sanders <jeremy at jeremysanders.net>
> Subject: [PyQt] QImage from Python buffer
> To: pyqt at riverbankcomputing.com
> Message-ID: <fppgaj$fiq$1 at ger.gmane.org>
> Content-Type: text/plain; charset=us-ascii
>
> Hi -
>
> Would it be possible to add support to create a QImage from a Python buffer
> object?
>
> I want to be able to quickly convert numpy arrays to QImages for display.
> Currently I have to convert the numpy to a string, then the string to a
> QImage.
>
> it would be nice to do
>
> QImage(numpyarray.data, 100, 100, QImage.Format_RGB32)
>
> where numpyarray is a 100x100x4 8 bit array.
>
> Thanks
>
> Jeremy
>
> --
> http://www.jeremysanders.net/
>

What you want is the toQImage function that is supplied as part of
the PyQwt package. The QwtImagePlotDemo.py example included with PyQwt
uses the function in a worked example.

Cheers

Tony
___________
Tony Willis
National Research Council   Tony.Willis at nrc-cnrc.gc.ca
Box 248                     (250)493-2277
Penticton, BC  V2A 6J9      fax: 493-7767
Government of Canada        Gouvernement du Canada



More information about the PyQt mailing list