The PySide.QtGui.QImageWriter class provides a format independent interface for writing images to files or other devices.
PySide.QtGui.QImageWriter supports setting format specific options, such as the gamma level, compression level and quality, prior to storing the image. If you do not need such options, you can use QImage.save() or QPixmap.save() instead.
To store an image, you start by constructing a PySide.QtGui.QImageWriter object. Pass either a file name or a device pointer, and the image format to PySide.QtGui.QImageWriter ‘s constructor. You can then set several options, such as the gamma level (by calling PySide.QtGui.QImageWriter.setGamma() ) and quality (by calling PySide.QtGui.QImageWriter.setQuality() ). PySide.QtGui.QImageWriter.canWrite() returns true if PySide.QtGui.QImageWriter can write the image (i.e., the image format is supported and the device is open for writing). Call PySide.QtGui.QImageWriter.write() to write the image to the device.
If any error occurs when writing the image, PySide.QtGui.QImageWriter.write() will return false. You can then call PySide.QtGui.QImageWriter.error() to find the type of error that occurred, or PySide.QtGui.QImageWriter.errorString() to get a human readable description of what went wrong.
Call PySide.QtGui.QImageWriter.supportedImageFormats() for a list of formats that PySide.QtGui.QImageWriter can write. PySide.QtGui.QImageWriter supports all built-in image formats, in addition to any image format plugins that support writing.
Constructs an empty PySide.QtGui.QImageWriter object. Before writing, you must call PySide.QtGui.QImageWriter.setFormat() to set an image format, then PySide.QtGui.QImageWriter.setDevice() or PySide.QtGui.QImageWriter.setFileName() .
Constructs a PySide.QtGui.QImageWriter object using the device device and image format format .
Constructs a PySide.QtGui.QImageWriter objects that will write to a file with the name fileName , using the image format format . If format is not provided, PySide.QtGui.QImageWriter will detect the image format by inspecting the extension of fileName .
This enum describes errors that can occur when writing images with PySide.QtGui.QImageWriter .
|QImageWriter.DeviceError||PySide.QtGui.QImageWriter encountered a device error when writing the image data. Consult your device for more details on what went wrong.|
|QImageWriter.UnsupportedFormatError||Qt does not support the requested image format.|
|QImageWriter.UnknownError||An unknown error occurred. If you get this value after calling PySide.QtGui.QImageWriter.write() , it is most likely caused by a bug in PySide.QtGui.QImageWriter .|
Returns true if PySide.QtGui.QImageWriter can write the image; i.e., the image format is supported and the assigned device is open for reading.
Returns the compression of the image.
Returns the device currently assigned to PySide.QtGui.QImageWriter , or 0 if no device has been assigned.
Returns the type of error that last occurred.
Returns a human readable description of the last error that occurred.
If the currently assigned device is a PySide.QtCore.QFile , or if PySide.QtGui.QImageWriter.setFileName() has been called, this function returns the name of the file PySide.QtGui.QImageWriter writes to. Otherwise (i.e., if no device has been assigned or the device is not a PySide.QtCore.QFile ), an empty PySide.QtCore.QString is returned.
Returns the format PySide.QtGui.QImageWriter uses for writing images.
Returns the gamma level of the image.
Returns the quality level of the image.
|Parameters:||compression – PySide.QtCore.int|
This is an image format specific function that set the compression of an image. For image formats that do not support setting the compression, this value is ignored.
The value range of compression depends on the image format. For example, the “tiff” format supports two values, 0(no compression) and 1(LZW-compression).
|Parameters:||device – PySide.QtCore.QIODevice|
If the device is not already open, PySide.QtGui.QImageWriter will attempt to open the device in QIODevice.WriteOnly mode by calling open(). Note that this does not work for certain devices, such as PySide.QtCore.QProcess , PySide.QtNetwork.QTcpSocket and PySide.QtNetwork.QUdpSocket , where more logic is required to open the device.
|Parameters:||fileName – unicode|
Sets the file name of PySide.QtGui.QImageWriter to fileName . Internally, PySide.QtGui.QImageWriter will create a PySide.QtCore.QFile and open it in QIODevice.WriteOnly mode, and use this file when writing images.
|Parameters:||format – PySide.QtCore.QByteArray|
Sets the format PySide.QtGui.QImageWriter will use when writing images, to format . format is a case insensitive text string. Example:
writer = QImageWriter() writer.setFormat("png") # same as writer.setFormat("PNG")
|Parameters:||gamma – PySide.QtCore.float|
This is an image format specific function that sets the gamma level of the image to gamma . For image formats that do not support setting the gamma level, this value is ignored.
The value range of gamma depends on the image format. For example, the “png” format supports a gamma range from 0.0 to 1.0.
|Parameters:||quality – PySide.QtCore.int|
This is an image format specific function that sets the quality level of the image to quality . For image formats that do not support setting the quality, this value is ignored.
The value range of quality depends on the image format. For example, the “jpeg” format supports a quality range from 0 (low quality, high compression) to 100 (high quality, low compression).
Sets the image text associated with the key key to text . This is useful for storing copyright information or other information about the image. Example:
image = QImage("some/image.jpeg") writer = QImageWriter("images/outimage.png", "png") writer.setText("Author", "John Smith") writer.write(image)
If you want to store a single block of data (e.g., a comment), you can pass an empty key, or use a generic key like “Description”.
The key and text will be embedded into the image data after calling PySide.QtGui.QImageWriter.write() .
Support for this option is implemented through QImageIOHandler.Description .
Returns the list of image formats supported by PySide.QtGui.QImageWriter .
By default, Qt can write the following formats:
|JPG||Joint Photographic Experts Group|
|JPEG||Joint Photographic Experts Group|
|PNG||Portable Network Graphics|
|TIFF||Tagged Image File Format|
Reading and writing SVG files is supported through Qt’s SVG Module .
Note that the PySide.QtGui.QApplication instance must be created before this function is called.
|Parameters:||option – PySide.QtGui.QImageIOHandler.ImageOption|
|Parameters:||image – PySide.QtGui.QImage|
Writes the image image to the assigned device or file name. Returns true on success; otherwise returns false. If the operation fails, you can call PySide.QtGui.QImageWriter.error() to find the type of error that occurred, or PySide.QtGui.QImageWriter.errorString() to get a human readable description of the error.