Skip to content

PythonQt.QtGui.QImageWriter

QImageWriter

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QImageWriter supports setting format specific options, such as 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 QImageWriter object. Pass either a file name or a device pointer, and the image format to QImageWriter's constructor. You can then set several options, such as quality (by calling setQuality()). canWrite() returns true if QImageWriter can write the image (i.e., the image format is supported and the device is open for writing). Call write() to write the image to the device.

If any error occurs when writing the image, write() will return false. You can then call error() to find the type of error that occurred, or errorString() to get a human readable description of what went wrong.

Call supportedImageFormats() for a list of formats that QImageWriter can write. QImageWriter supports all built-in image formats, in addition to any image format plugins that support writing.

Note: QImageWriter assumes exclusive control over the file or device that is assigned. Any attempts to modify the assigned file or device during the lifetime of the QImageWriter object will yield undefined results. If immediate access to a resource is desired, the use of a scope is the recommended method.

For example:

    QString imagePath(QStringLiteral("path/image.jpeg"));
    QImage image(64, 64, QImage::Format_RGB32);
    image.fill(Qt::red);
    {
        QImageWriter writer(imagePath);
        writer.write(image);
    }

    QFile::rename(imagePath,
                  QStringLiteral("path/other_image.jpeg"));

Source: https://doc.qt.io/archives/qt-5.15/qimagewriter.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
DeviceError attribute Any (shared captured text)
ImageWriterError attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
UnknownError attribute Any (shared captured text)
UnsupportedFormatError attribute Any (shared captured text)
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
canWrite function (self) -> bool X.canWrite() -> bool
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
compression function (self) -> int X.compression() -> int
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
device function (self) -> Any X.device() -> PythonQt.QtCore.QIODevice
error function (self) -> Any Returns the type of error that last occurred.
errorString function (self) -> str X.errorString() -> str
fileName function (self) -> str X.fileName() -> str
format function (self) -> Any X.format() -> PythonQt.QtCore.QByteArray
gamma function (self) -> float X.gamma() -> float
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
optimizedWrite function (self) -> bool X.optimizedWrite() -> bool
progressiveScanWrite function (self) -> bool X.progressiveScanWrite() -> bool
quality function (self) -> int X.quality() -> int
setCompression function (self, compression: int) -> None This is an image format specific function that set the compression of an image.
setDevice function (self, device: Any) -> None Sets [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html)'s device to device.
setFileName function (self, fileName: str) -> None Sets the file name of [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html) to fileName.
setFormat function (self, format: Any) -> None You can call [supportedImageFormats](https://doc.qt.io/archives/qt-5.15/qimagewriter.html#supportedImageFormats)() for the full list of formats…
setGamma function (self, gamma: float) -> None
setOptimizedWrite function (self, optimize: bool) -> None This is an image format-specific function which sets the optimize flags when writing images.
setProgressiveScanWrite function (self, progressive: bool) -> None This is an image format-specific function which turns on progressive scanning when writing images.
setQuality function (self, quality: int) -> None Sets the quality setting of the image format to quality.
setSubType function (self, type: Any) -> None This is an image format specific function that sets the subtype of the image to type.
setText function (self, key: str, text: str) -> None X.setText(key, text)
subType function (self) -> Any X.subType() -> PythonQt.QtCore.QByteArray
supportedImageFormats function (self) -> Any Returns the list of image formats supported by [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html).
supportedMimeTypes function (self) -> Any Returns the list of MIME types supported by [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html).
supportedSubTypes function (self) -> Any Returns the list of subtypes supported by an image.
supportsOption function (self, option: Any) -> bool X.supportsOption(option) -> bool
tr function (self, sourceText: Any, disambiguation: Any, n: Any) -> str X.tr(sourceText, disambiguation, n) -> str (shared captured text)
trUtf8 function (self, sourceText: Any, disambiguation: Any, n: Any) -> str X.trUtf8(sourceText, disambiguation, n) -> str (shared captured text)
write function (self, image: Any) -> bool X.write(image) -> bool