[PyKDE] (transparent) PIL image to QImage conversion?

Orcan Ogetbil orcan at psu.edu
Sun Apr 23 23:38:38 BST 2006


On Sun, 2006-04-23 at 23:20 +0200, David Boddie wrote: 
> On Thu, 6 Apr 2006 16:37:07, "ORCAN OGETBIL" wrote:
> 
> > 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 get 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:
> > http://mail.python.org/pipermail/image-sig/2004-September/002908.html
> >
> > Has anybody encountered this problem?
> > Can I use cStringIO.StringIO() instead of PIL's tostring() somehow?
> > Any solutions?
> 
> If you haven't already solved this problem, you might want to try saving
> the contents of the Image to a StringIO object then reading the data
> stored in the StringIO into a QImage. Try something like this:
> 
>   # im is an existing PIL Image object.
>   from qt import QImage
>   from cStringIO import StringIO
>   s = StringIO()
>   im.save(s, "PNG")
>   s.seek(0)
>   image = QImage()
>   image.loadFromData(s.read())
> 
> Hope this is useful,
> 
> David

Thank you, it works this way. Apparently I forgot to put the the line
with the seek() function. I knew it was so easy.
Thanks again.

Orcan




More information about the PyQt mailing list