[PyQt] Conversion problem from QImage to QPixmap

Daniele Esposti expo at expobrain.net
Fri Aug 27 15:46:30 BST 2010


Hi Nicola,

fromImage()  is a static method, so change your code like that:

pix = QPixmap.fromImage( img )


On 27 August 2010 15:21, Nicola Creati <ncreati at inogs.it> wrote:
> Hello,
> I'm having troubles trying to convert from a QImage to a QPixmap. The
> resulting QPixmap is always invalid (isNull method is always True). This is
> a short code that reproduce my problem:
>
>
> from PyQt4.QtGui import *
> from PyQt4.QtCore import *
> import sys
>
> app = QApplication(sys.argv)
>
> img = QImage("image.jpeg")
>
> pix = QPixmap()
> pix.fromImage(img)
> pix.save("output.jpeg", 'JPEG')
>
> l = QLabel()
> l.setPixmap(pix)
> l.show()
>
> app.exec_()
>
> The Qlabel shows nothing and no image file is saved from the QPixmap object
> pix. I have tried with several different image file but I got always the
> same result.
>
> Please, can someone help?
>
> Nicola
>
> --
> Nicola Creati
> Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS
> www.inogs.it Dipartimento di Geofisica della Litosfera Geophysics of
> Lithosphere Department CARS (Cartography and Remote Sensing) Research Group
> http://www.inogs.it/Cars/ Borgo Grotta Gigante 42/c 34010 Sgonico - Trieste
> - ITALY ncreati at ogs.trieste.it
> off.   +39 040 2140 213
> fax.   +39 040 327307
>
> _____________________________________________________________________
> This communication, that may contain confidential and/or legally privileged
> information, is intended solely for the use of the intended addressees.
> Opinions, conclusions and other information contained in this message, that
> do not relate to the official business of OGS, shall be considered as not
> given or endorsed by it. Every opinion or advice contained in this
> communication is subject to the terms and conditions provided by the
> agreement governing the engagement with such a client. Any use, disclosure,
> copying or distribution of the contents of this communication by a
> not-intended recipient or in violation of the purposes of this communication
> is strictly prohibited and may be unlawful. For Italy only: Ai sensi del
> D.Lgs.196/2003 - "T.U. sulla Privacy" si precisa che le informazioni
> contenute in questo messaggio sono riservate ed a uso esclusivo del
> destinatario.
> _____________________________________________________________________
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



-- 
Daniele Esposti


More information about the PyQt mailing list