读写图像文件

读取图像的最常见方式是透过 QImage and QPixmap 's constructors, or by calling the QImage::load () 和 QPixmap::load () functions. In addition, Qt provides the QImageReader class which gives more control over the process. Depending on the underlying support in the image format, the functions provided by the class can save memory and speed up loading of images.

Likewise, Qt provides the QImageWriter class which 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 () 或 QPixmap::save () 代替。

QMovie

QMovie is a convenience class for displaying animations, using the QImageReader class internally. Once created, the QMovie class provides various functions for both running and controlling the given animation.

QImageReader and QImageWriter classes rely on the QImageIOHandler class which is the common image I/O interface for all image formats in Qt. QImageIOHandler objects are used internally by QImageReader and QImageWriter to add support for different image formats to Qt.

A list of the supported file formats are available through the QImageReader::supportedImageFormats () 和 QImageWriter::supportedImageFormats () functions. Qt supports several file formats by default, and in addition new formats can be added as plugins. The currently supported formats are listed in the QImageReader and QImageWriter 类文档编制。

Qt's plugin mechanism can also be used to write a custom image format handler. This is done by deriving from the QImageIOHandler class, and creating a QImageIOPlugin object which is a factory for creating QImageIOHandler objects. When the plugin is installed, QImageReader and QImageWriter will automatically load the plugin and start using it.