[PyKDE] How to display GIF and JPEG

Gey-Hong Gweon gweon at umich.edu
Fri Mar 30 19:19:30 BST 2001


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.&nbsp;&nbsp; I'll look into using
 > loadFromData.&nbsp;&nbsp;&nbsp;&nbsp; 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&nbsp; 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>
 > &gt;Thank for the source code.&nbsp;&nbsp; I guess saving it first as PNG
 > first is a <br>
 > &gt;possible solution :-)<br>
 > &gt;Still, is there anyway to load the image into memory directly without
 > <br>
 > &lt;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&amp;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)




More information about the PyQt mailing list