[Image-SIG] (transparent) PIL image to QImage conversion?

Orcan Ogetbil oogetbil at phys.psu.edu
Sat Apr 8 21:10:33 CEST 2006

I need to convert a PIL image to a QImage object so I
can display it in a PyQt application. I found a basic example at:


There the PIL image is converted to a string using a jpeg encoder first;
then the string is converted to a QByteArray;
then Qimage's loadFromData() function is used for the final conversion to a
QImage object.

My problem is, the JPEG encoding kills the transparency of my PNG images.
When I
do RAW encoding, I get nothing from the QByteArray object. I also couldn't
the thing work with a GIF encoding. PIL's tostring() function doesn't support
PNG encoding.

Here I found a list of encodings PIL provides:

Has anybody encountered this problem?
Can I use cStringIO.StringIO() instead of PIL's tostring() somehow?
Any solutions?


More information about the Image-SIG mailing list