[PyKDE] How to display GIF and JPEG
Sheng-Te Tsao
shengte.tsao at firsttick.com
Fri Mar 30 22:47:54 BST 2001
Thanks, I guess what I need to figure out is a way to tell PIL to output in
some format that is close to what QT uses internally (my guess is that BMP
or XBM fits the bill) then there should not be too much overhead from the
conversion. Still, just like you I wish there is a more direct approach
by writing some glue code (preferably in Python) that hooks up the PIL JPG
decoder and QT so that there is no conversion.
Sheng-Te
At 12:17 PM 3/30/2001 -0500, Gey-Hong Gweon wrote:
>I just ran the following code segment in my PyQt program to perhaps do
>something similar to what you want to do without creating files. I hope
>this is helpful. As commented, I wonder if there is a way to do away
>with the "png" step somehow...?
>
>import Image
>image = Image.open ('Desktop/misc/picture/munch.scream.jpg')
>import StringIO
>s = StringIO.StringIO ()
># Could the following three lines be simplified somehow??
>image.save (s, format = 'png')
>p = QPixmap ()
>p.loadFromData (s.getvalue ())
>gds.mdi.setBackgroundPixmap (p)
>
>On Fri March/30/2001, 11:58:46 -0500, Sheng-Te Tsao wrote:
> > Thanks for the tips. I'll look into using loadFromData. Of
> course, if
> > someone has done this already, some sample code would be appreciated :-)
> >
> > Sheng-Te
> >
> > At 06:43 PM 3/30/2001 +0200, Gerard Vermeulen wrote:
> > >Of course, the example is a dumb solution. If you want to keep
> > >everything in memory, I would explore the following:
> > >
> > >(1) use memory mapped files: look in the Python library reference for
> > >mmap. This supposes that the PythonWare Image Library and Qt are
> > >willing to read/write those files.
> > >
> > >(2) convert the PIL image to a string (see PIL doc), possibly make
> > >a QByteArray out of it and use loadFromData
> > >
> > >(3) use PIL to make a mmap, use all data of the mmapped file
> > >as QByteArray in loadFromData
> > >
> > >(4) switch to Linux or buy Qt
> > >
> > >:-) Gerard
> > >
> > >Sheng-Te Tsao wrote:
> > > >Thank for the source code. I guess saving it first as PNG first is a
> > > >possible solution :-)
> > > >Still, is there anyway to load the image into memory directly without
> > ><having to save it as PNG first?
> >
> >
> > Sheng-Te Tsao
> > Online Status:
> >
> <http://eudora.voicecontact.com/vc3/?tst%40eudoramail.com><http://eudora.voicecontact.com/vc3/?tst%40eudoramail.com><http://www.eudora.com/products/voicecontact/>
> >
> > <html>
> > Thanks for the tips. I'll look into using
> > loadFromData. Of course, if someone has done this
> > already, some sample code would be appreciated :-)<br>
> > <br>
> > Sheng-Te<br>
> > <br>
> > At 06:43 PM 3/30/2001 +0200, Gerard Vermeulen wrote:<br>
> > <blockquote type=cite class=cite cite>Of course, the example is a dumb
> > solution. If you want to keep<br>
> > everything in memory, I would explore the following:<br>
> > <br>
> > (1) use memory mapped files: look in the Python library reference
> > for<br>
> > mmap. This supposes that the PythonWare Image Library and Qt are<br>
> > willing to read/write those files.<br>
> > <br>
> > (2) convert the PIL image to a string (see PIL doc), possibly make <br>
> > a QByteArray out of it and use loadFromData<br>
> > <br>
> > (3) use PIL to make a mmap, use all data of the mmapped file<br>
> > as QByteArray in loadFromData<br>
> > <br>
> > (4) switch to Linux or buy Qt <br>
> > <br>
> > :-) Gerard<br>
> > <br>
> > Sheng-Te Tsao wrote:<br>
> > >Thank for the source code. I guess saving it first as PNG
> > first is a <br>
> > >possible solution :-)<br>
> > >Still, is there anyway to load the image into memory directly without
> > <br>
> > <having to save it as PNG first?</blockquote><br>
> > <!-- VC_SIGTAG --><br>Sheng-Te
> > Tsao<br><table cellpadding=2 cellspacing=3 bgcolor=#ffffff><tr><td>Online
> > Status:
> > <a
> href="http://eudora.voicecontact.com/vc3/?tst%40eudoramail.com"><img
> NOSEND=1 height=16 width=100 border=0
> src="http://eudora.voicecontact.com/servlets/presence?imgbase=status%252Fvc2final_email&channel=HEARME_VC20.SDK.%2523tst%40eudoramail.com"></a></td><td><a
> href="http://eudora.voicecontact.com/vc3/?tst%40eudoramail.com"><img
> border=0 NOSEND=1 height=25 width=75
> src="http://eudora.voicecontact.com/vc3/images/email/vc2final/emailbtn_callsender.gif"></a></td><td><a
> href="http://www.eudora.com/products/voicecontact/"><img border=0
> NOSEND=1 height=25 width=135
> src="http://eudora.voicecontact.com/vc3/images/email/vc2final/download_eudora.gif"></a></td></tr></table><br></html>
>
>--
>Gey-Hong Gweon, Research Fellow, Ph.D.
>Randall Lab. of Physics, Univ. of Michigan, Ann Arbor, MI 48109-1120
>(734) 647-9434 (Office), 763-3417 (Lab), 763-9694 (Fax)
Sheng-Te Tsao
Online Status:
<http://eudora.voicecontact.com/vc3/?tst%40eudoramail.com><http://eudora.voicecontact.com/vc3/?tst%40eudoramail.com><http://www.eudora.com/products/voicecontact/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20010330/eea253f2/attachment.html
More information about the PyQt
mailing list