Skip to content

PythonQt.Qt.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. (shared captured text)
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 (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
compression function (self) -> int X.compression() -> int (shared captured text)
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 (shared captured text)
error function (self) -> Any Returns the type of error that last occurred. (shared captured text)
errorString function (self) -> str X.errorString() -> str (shared captured text)
fileName function (self) -> str X.fileName() -> str (shared captured text)
format function (self) -> Any X.format() -> PythonQt.QtCore.QByteArray (shared captured text)
gamma function (self) -> float X.gamma() -> float (shared captured text)
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 (shared captured text)
progressiveScanWrite function (self) -> bool X.progressiveScanWrite() -> bool (shared captured text)
quality function (self) -> int X.quality() -> int (shared captured text)
setCompression function (self, compression: int) -> None This is an image format specific function that set the compression of an image. (shared captured text)
setDevice function (self, device: Any) -> None Sets [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html)'s device to device. (shared captured text)
setFileName function (self, fileName: str) -> None Sets the file name of [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html) to fileName. (shared captured text)
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… (shared captured text)
setGamma function (self, gamma: float) -> None (shared captured text)
setOptimizedWrite function (self, optimize: bool) -> None This is an image format-specific function which sets the optimize flags when writing images. (shared captured text)
setProgressiveScanWrite function (self, progressive: bool) -> None This is an image format-specific function which turns on progressive scanning when writing images. (shared captured text)
setQuality function (self, quality: int) -> None Sets the quality setting of the image format to quality. (shared captured text)
setSubType function (self, type: Any) -> None This is an image format specific function that sets the subtype of the image to type. (shared captured text)
setText function (self, key: str, text: str) -> None X.setText(key, text) (shared captured text)
subType function (self) -> Any X.subType() -> PythonQt.QtCore.QByteArray (shared captured text)
supportedImageFormats function (self) -> Any Returns the list of image formats supported by [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html). (shared captured text)
supportedMimeTypes function (self) -> Any Returns the list of MIME types supported by [QImageWriter](https://doc.qt.io/archives/qt-5.15/qimagewriter.html). (shared captured text)
supportedSubTypes function (self) -> Any Returns the list of subtypes supported by an image. (shared captured text)
supportsOption function (self, option: Any) -> bool X.supportsOption(option) -> bool (shared captured text)
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 (shared captured text)