Struct qt_gui::QImageWriter

source ·
#[repr(C)]
pub struct QImageWriter { /* private fields */ }
Expand description

The QImageWriter class provides a format independent interface for writing images to files or other devices.

C++ class: QImageWriter.

C++ documentation:

The QImageWriter class provides a format independent interface for writing images to files or other devices.

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 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 the gamma level (by calling setGamma()) and 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.

Implementations§

source§

impl QImageWriter

source

pub unsafe fn can_write(&self) -> bool

Returns true if QImageWriter can write the image; i.e., the image format is supported and the assigned device is open for reading.

Calls C++ function: bool QImageWriter::canWrite() const.

C++ documentation:

Returns true if QImageWriter can write the image; i.e., the image format is supported and the assigned device is open for reading.

See also write(), setDevice(), and setFormat().

source

pub unsafe fn compression(&self) -> c_int

Returns the compression of the image.

Calls C++ function: int QImageWriter::compression() const.

C++ documentation:

Returns the compression of the image.

See also setCompression().

source

pub unsafe fn description(&self) -> CppBox<QString>

Use QImageReader::text() instead.

Calls C++ function: QString QImageWriter::description() const.

C++ documentation:

Use QImageReader::text() instead.

Returns the description of the image.

See also setDescription().

source

pub unsafe fn device(&self) -> QPtr<QIODevice>

Returns the device currently assigned to QImageWriter, or 0 if no device has been assigned.

Calls C++ function: QIODevice* QImageWriter::device() const.

C++ documentation:

Returns the device currently assigned to QImageWriter, or 0 if no device has been assigned.

See also setDevice().

source

pub unsafe fn error(&self) -> ImageWriterError

Returns the type of error that last occurred.

Calls C++ function: QImageWriter::ImageWriterError QImageWriter::error() const.

C++ documentation:

Returns the type of error that last occurred.

See also ImageWriterError and errorString().

source

pub unsafe fn error_string(&self) -> CppBox<QString>

Returns a human readable description of the last error that occurred.

Calls C++ function: QString QImageWriter::errorString() const.

C++ documentation:

Returns a human readable description of the last error that occurred.

See also error().

source

pub unsafe fn file_name(&self) -> CppBox<QString>

If the currently assigned device is a QFile, or if setFileName() has been called, this function returns the name of the file QImageWriter writes to. Otherwise (i.e., if no device has been assigned or the device is not a QFile), an empty QString is returned.

Calls C++ function: QString QImageWriter::fileName() const.

C++ documentation:

If the currently assigned device is a QFile, or if setFileName() has been called, this function returns the name of the file QImageWriter writes to. Otherwise (i.e., if no device has been assigned or the device is not a QFile), an empty QString is returned.

See also setFileName() and setDevice().

source

pub unsafe fn format(&self) -> CppBox<QByteArray>

Returns the format QImageWriter uses for writing images.

Calls C++ function: QByteArray QImageWriter::format() const.

C++ documentation:

Returns the format QImageWriter uses for writing images.

See also setFormat().

source

pub unsafe fn gamma(&self) -> c_float

Returns the gamma level of the image.

Calls C++ function: float QImageWriter::gamma() const.

C++ documentation:

Returns the gamma level of the image.

See also setGamma().

source

pub unsafe fn image_formats_for_mime_type( mime_type: impl CastInto<Ref<QByteArray>> ) -> CppBox<QListOfQByteArray>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the list of image formats corresponding to mimeType.

Calls C++ function: static QList<QByteArray> QImageWriter::imageFormatsForMimeType(const QByteArray& mimeType).

C++ documentation:

Returns the list of image formats corresponding to mimeType.

Note that the QGuiApplication instance must be created before this function is called.

This function was introduced in Qt 5.12.

See also supportedImageFormats() and supportedMimeTypes().

source

pub unsafe fn new() -> CppBox<QImageWriter>

Constructs an empty QImageWriter object. Before writing, you must call setFormat() to set an image format, then setDevice() or setFileName().

Calls C++ function: [constructor] void QImageWriter::QImageWriter().

C++ documentation:

Constructs an empty QImageWriter object. Before writing, you must call setFormat() to set an image format, then setDevice() or setFileName().

source

pub unsafe fn from_q_io_device_q_byte_array( device: impl CastInto<Ptr<QIODevice>>, format: impl CastInto<Ref<QByteArray>> ) -> CppBox<QImageWriter>

Constructs a QImageWriter object using the device device and image format format.

Calls C++ function: [constructor] void QImageWriter::QImageWriter(QIODevice* device, const QByteArray& format).

C++ documentation:

Constructs a QImageWriter object using the device device and image format format.

source

pub unsafe fn from_q_string_q_byte_array( file_name: impl CastInto<Ref<QString>>, format: impl CastInto<Ref<QByteArray>> ) -> CppBox<QImageWriter>

Constructs a QImageWriter objects that will write to a file with the name fileName, using the image format format. If format is not provided, QImageWriter will detect the image format by inspecting the extension of fileName.

Calls C++ function: [constructor] void QImageWriter::QImageWriter(const QString& fileName, const QByteArray& format = …).

C++ documentation:

Constructs a QImageWriter objects that will write to a file with the name fileName, using the image format format. If format is not provided, QImageWriter will detect the image format by inspecting the extension of fileName.

source

pub unsafe fn from_q_string( file_name: impl CastInto<Ref<QString>> ) -> CppBox<QImageWriter>

Constructs a QImageWriter objects that will write to a file with the name fileName, using the image format format. If format is not provided, QImageWriter will detect the image format by inspecting the extension of fileName.

Calls C++ function: [constructor] void QImageWriter::QImageWriter(const QString& fileName).

C++ documentation:

Constructs a QImageWriter objects that will write to a file with the name fileName, using the image format format. If format is not provided, QImageWriter will detect the image format by inspecting the extension of fileName.

source

pub unsafe fn optimized_write(&self) -> bool

Returns whether optimization has been turned on for writing the image.

Calls C++ function: bool QImageWriter::optimizedWrite() const.

C++ documentation:

Returns whether optimization has been turned on for writing the image.

This function was introduced in Qt 5.5.

See also setOptimizedWrite().

source

pub unsafe fn progressive_scan_write(&self) -> bool

Returns whether the image should be written as a progressive image.

Calls C++ function: bool QImageWriter::progressiveScanWrite() const.

C++ documentation:

Returns whether the image should be written as a progressive image.

This function was introduced in Qt 5.5.

See also setProgressiveScanWrite().

source

pub unsafe fn quality(&self) -> c_int

Returns the quality setting of the image format.

Calls C++ function: int QImageWriter::quality() const.

C++ documentation:

Returns the quality setting of the image format.

See also setQuality().

source

pub unsafe fn set_compression(&self, compression: c_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.

Calls C++ function: void QImageWriter::setCompression(int compression).

C++ documentation:

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).

See also compression().

source

pub unsafe fn set_description(&self, description: impl CastInto<Ref<QString>>)

Use setText() instead.

Calls C++ function: void QImageWriter::setDescription(const QString& description).

C++ documentation:

Use setText() instead.

This is an image format specific function that sets the description of the image to description. For image formats that do not support setting the description, this value is ignored.

The contents of description depends on the image format.

See also description().

source

pub unsafe fn set_device(&self, device: impl CastInto<Ptr<QIODevice>>)

Sets QImageWriter's device to device. If a device has already been set, the old device is removed from QImageWriter and is otherwise left unchanged.

Calls C++ function: void QImageWriter::setDevice(QIODevice* device).

C++ documentation:

Sets QImageWriter’s device to device. If a device has already been set, the old device is removed from QImageWriter and is otherwise left unchanged.

If the device is not already open, 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 QProcess, QTcpSocket and QUdpSocket, where more logic is required to open the device.

See also device() and setFileName().

source

pub unsafe fn set_file_name(&self, file_name: impl CastInto<Ref<QString>>)

Sets the file name of QImageWriter to fileName. Internally, QImageWriter will create a QFile and open it in QIODevice::WriteOnly mode, and use this file when writing images.

Calls C++ function: void QImageWriter::setFileName(const QString& fileName).

C++ documentation:

Sets the file name of QImageWriter to fileName. Internally, QImageWriter will create a QFile and open it in QIODevice::WriteOnly mode, and use this file when writing images.

See also fileName() and setDevice().

source

pub unsafe fn set_format(&self, format: impl CastInto<Ref<QByteArray>>)

Sets the format QImageWriter will use when writing images, to format. format is a case insensitive text string. Example:

Calls C++ function: void QImageWriter::setFormat(const QByteArray& format).

C++ documentation:

Sets the format QImageWriter will use when writing images, to format. format is a case insensitive text string. Example:


  QImageWriter writer;
  writer.setFormat("png"); // same as writer.setFormat("PNG");

You can call supportedImageFormats() for the full list of formats QImageWriter supports.

See also format().

source

pub unsafe fn set_gamma(&self, gamma: c_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.

Calls C++ function: void QImageWriter::setGamma(float gamma).

C++ documentation:

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.

See also gamma() and quality().

source

pub unsafe fn set_optimized_write(&self, optimize: bool)

This is an image format-specific function which sets the optimize flags when writing images. For image formats that do not support setting an optimize flag, this value is ignored.

Calls C++ function: void QImageWriter::setOptimizedWrite(bool optimize).

C++ documentation:

This is an image format-specific function which sets the optimize flags when writing images. For image formats that do not support setting an optimize flag, this value is ignored.

The default is false.

This function was introduced in Qt 5.5.

See also optimizedWrite().

source

pub unsafe fn set_progressive_scan_write(&self, progressive: bool)

This is an image format-specific function which turns on progressive scanning when writing images. For image formats that do not support setting a progressive scan flag, this value is ignored.

Calls C++ function: void QImageWriter::setProgressiveScanWrite(bool progressive).

C++ documentation:

This is an image format-specific function which turns on progressive scanning when writing images. For image formats that do not support setting a progressive scan flag, this value is ignored.

The default is false.

This function was introduced in Qt 5.5.

See also progressiveScanWrite().

source

pub unsafe fn set_quality(&self, quality: c_int)

Sets the quality setting of the image format to quality.

Calls C++ function: void QImageWriter::setQuality(int quality).

C++ documentation:

Sets the quality setting of the image format to quality.

Some image formats, in particular lossy ones, entail a tradeoff between a) visual quality of the resulting image, and b) encoding execution time and compression level. This function sets the level of that tradeoff for image formats that support it. For other formats, 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 visual quality, high compression) to 100 (high visual quality, low compression).

See also quality().

source

pub unsafe fn set_sub_type(&self, type_: impl CastInto<Ref<QByteArray>>)

This is an image format specific function that sets the subtype of the image to type. Subtype can be used by a handler to determine which format it should use while saving the image.

Calls C++ function: void QImageWriter::setSubType(const QByteArray& type).

C++ documentation:

This is an image format specific function that sets the subtype of the image to type. Subtype can be used by a handler to determine which format it should use while saving the image.

For example, saving an image in DDS format with A8R8G8R8 subtype:

QImageWriter writer(“some/image.dds”); if (writer.supportsOption(QImageIOHandler::SubType)) writer.setSubType(“A8R8G8B8”); writer.write(image);

This function was introduced in Qt 5.4.

See also subType().

source

pub unsafe fn set_text( &self, key: impl CastInto<Ref<QString>>, text: impl CastInto<Ref<QString>> )

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:

Calls C++ function: void QImageWriter::setText(const QString& key, const QString& text).

C++ documentation:

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:


  QImage image("some/image.jpeg");
  QImageWriter writer("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 write().

Support for this option is implemented through QImageIOHandler::Description.

This function was introduced in Qt 4.1.

See also QImage::setText() and QImageReader::text().

source

pub unsafe fn set_transformation(&self, orientation: QFlags<Transformation>)

Sets the image transformations metadata including orientation to transform.

Calls C++ function: void QImageWriter::setTransformation(QFlags<QImageIOHandler::Transformation> orientation).

C++ documentation:

Sets the image transformations metadata including orientation to transform.

If transformation metadata is not supported by the image format, the transform is applied before writing.

This function was introduced in Qt 5.5.

See also transformation() and write().

source

pub unsafe fn sub_type(&self) -> CppBox<QByteArray>

Returns the subtype of the image.

Calls C++ function: QByteArray QImageWriter::subType() const.

C++ documentation:

Returns the subtype of the image.

This function was introduced in Qt 5.4.

See also setSubType().

source

pub unsafe fn supported_image_formats() -> CppBox<QListOfQByteArray>

Returns the list of image formats supported by QImageWriter.

Calls C++ function: static QList<QByteArray> QImageWriter::supportedImageFormats().

C++ documentation:

Returns the list of image formats supported by QImageWriter.

By default, Qt can write the following formats:

FormatMIME typeDescription
BMPimage/bmpWindows Bitmap
JPGimage/jpegJoint Photographic Experts Group
PNGimage/pngPortable Network Graphics
PBMimage/x-portable-bitmapPortable Bitmap
PGMimage/x-portable-graymapPortable Graymap
PPMimage/x-portable-pixmapPortable Pixmap
XBMimage/x-xbitmapX11 Bitmap
XPMimage/x-xpixmapX11 Pixmap

Reading and writing SVG files is supported through the Qt SVG module. The Qt Image Formats module provides support for additional image formats.

Note that the QApplication instance must be created before this function is called.

See also setFormat(), QImageReader::supportedImageFormats(), and QImageIOPlugin.

source

pub unsafe fn supported_mime_types() -> CppBox<QListOfQByteArray>

Returns the list of MIME types supported by QImageWriter.

Calls C++ function: static QList<QByteArray> QImageWriter::supportedMimeTypes().

C++ documentation:

Returns the list of MIME types supported by QImageWriter.

Note that the QApplication instance must be created before this function is called.

See also supportedImageFormats() and QImageReader::supportedMimeTypes().

source

pub unsafe fn supported_sub_types(&self) -> CppBox<QListOfQByteArray>

Returns the list of subtypes supported by an image.

Calls C++ function: QList<QByteArray> QImageWriter::supportedSubTypes() const.

C++ documentation:

Returns the list of subtypes supported by an image.

This function was introduced in Qt 5.4.

source

pub unsafe fn supports_option(&self, option: ImageOption) -> bool

Returns true if the writer supports option; otherwise returns false.

Calls C++ function: bool QImageWriter::supportsOption(QImageIOHandler::ImageOption option) const.

C++ documentation:

Returns true if the writer supports option; otherwise returns false.

Different image formats support different options. Call this function to determine whether a certain option is supported by the current format. For example, the PNG format allows you to embed text into the image's metadata (see text()).

QImageWriter writer(fileName); if (writer.supportsOption(QImageIOHandler::Description)) writer.setText(“Author”, “John Smith”);

Options can be tested after the writer has been associated with a format.

This function was introduced in Qt 4.2.

See also QImageReader::supportsOption() and setFormat().

source

pub unsafe fn tr( source_text: *const c_char, disambiguation: *const c_char, n: c_int ) -> CppBox<QString>

Calls C++ function: static QString QImageWriter::tr(const char* sourceText, const char* disambiguation, int n).

source

pub unsafe fn tr_utf8( source_text: *const c_char, disambiguation: *const c_char, n: c_int ) -> CppBox<QString>

Calls C++ function: static QString QImageWriter::trUtf8(const char* sourceText, const char* disambiguation, int n).

source

pub unsafe fn transformation(&self) -> QFlags<Transformation>

Returns the transformation and orientation the image has been set to written with.

Calls C++ function: QFlags<QImageIOHandler::Transformation> QImageWriter::transformation() const.

C++ documentation:

Returns the transformation and orientation the image has been set to written with.

This function was introduced in Qt 5.5.

See also setTransformation().

source

pub unsafe fn write(&self, image: impl CastInto<Ref<QImage>>) -> bool

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 error() to find the type of error that occurred, or errorString() to get a human readable description of the error.

Calls C++ function: bool QImageWriter::write(const QImage& image).

C++ documentation:

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 error() to find the type of error that occurred, or errorString() to get a human readable description of the error.

See also canWrite(), error(), and errorString().

Trait Implementations§

source§

impl CppDeletable for QImageWriter

source§

unsafe fn delete(&self)

Destructs the QImageWriter object.

Calls C++ function: [destructor] void QImageWriter::~QImageWriter().

C++ documentation:

Destructs the QImageWriter object.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.