[PyKDE] How to display GIF and JPEG
Gerard Vermeulen
gvermeul at labs.polycnrs-gre.fr
Thu Mar 29 09:23:03 BST 2001
Here is an example, which fills the background of
a future killer app with .gif or .jpg picture.
--START--#!/usr/bin/env python
import sys
from qt import *
import Image # the PythonWare Imaging Library
class Viewer(QWidget):
def __init__(self, filename, *args):
apply(QWidget.__init__, (self,) + args)
self.pixmap = QPixmap()
#if not self.pixmap.load(filename): # Qt2/Linux loads *.gif and *.jpg!
if 1:
print 'Could not load "%s", converting to "%s.png"' % \
(filename, filename)
image = Image.open(filename)
image.save(filename + '.png') # saved format depends on extension
self.pixmap.load(filename + '.png')
self.setBackgroundPixmap(self.pixmap)
app = QApplication(sys.argv)
# lena.gif and lena.jpg are included in the PythonWare Imaging Library
demo = Viewer("lena.jpg") # or demo = Viewer("lena.gif")
app.setMainWidget(demo)
demo.show()
app.exec_loop()
--END--
However, on Mandrake-Linux-7.2 and Qt-2.2.1 it works without
the PythonWare Image Library. Therefore I had to replace the
if not self ....
by
if 1:
Gerard Vermeulen
Sheng-Te Tsao wrote:
> Thanks for the info, but I only found support for tk and windows in that
> library. Is there any code that shows how
> to use PIL with QT's QImageIO extension?
> ST
> At 09:42 AM 3/28/2001 +0200, Gerard Vermeulen wrote:
> >Sheng-Te Tsao wrote:
> > >I am wondering if someone can show me some code that demonstrates how to
> > >read GIF or JPEG files using PyQT because unlike PNG, they are not compiled
> > >into the qt221.dll supplied with PyQT for Windows. Note that I do have
> > >access to the QT source code for Windows yet, although I do plan to buy a
> > >license in the near future, once I convince my company that PyQT is the way
> > >to go.
> >
> >Take a look at the PythonWare Image library
> >
> >http://www.pythonware.com/downloads/index.htm
> >
> >It should allow you to convert the GIF/JPEG files in memory to a format
> >that can be displayed by Qt.
More information about the PyQt
mailing list