image lib & Qt4

Fredrik Lundh fredrik at pythonware.com
Sat Jun 3 04:42:27 EDT 2006


Fredrik Lundh wrote:

>> To get better performance, you should be able to use PIL's tostring() 
>> method together with the QImage(buffer, width, height, depth, 
>> colortable, numColors, bitOrder) form of the QImage constructor.

I've posted a simple ImageQt interface module for PIL and PyQt4 here:

     http://svn.effbot.python-hosting.com/stuff/sandbox/pil/ImageQt.py

this interface handles 1, P, L, and RGB images efficiently.  usage:

     im = Image.open(...) # or some other pil operation

     qim = ImageQt.toimage(im)

     # to access the QImage, use qim.image.  e.g:

     label.setPixmap(QtGui.QPixmap.fromImage(qim.image))

note that the toimage() function returns a wrapper object, not a QImage 
instance.  I didn't find a reliable way to subclass from QImage, nor any 
other way to attach custom attributes to an existing QImage object.  if 
anyone knows how to do that, let me know.

</F>




More information about the Python-list mailing list