image lib & Qt4

Fredrik Lundh fredrik at pythonware.com
Fri Jun 2 02:01:26 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.

for PyQt4, that seems to have changed to QImage(buffer, width, height, 
format), where format is a QImage.Format_XXX specifier.

in other words, this should work:

	if im.mode != "RGB":
	    im = im.convert("RGB")

	data = im.tostring("raw", "BGRX")

	image = QImage(data, im.size[0], im.size[1],
			QImage.Format_RGB32)
	
note that the QImage descriptor will point into the data buffer, so you 
must hang on to data for as long you're using image.

(I haven't found a way to attach a user attribute to a QImage class; it 
doesn't complain when I do that, but it doesn't seem to do the right 
thing...)

</F>




More information about the Python-list mailing list