读取图像的最常见方式是透过
QImageandQPixmap‘s constructors, or by calling theload()andload()functions. In addition, Qt provides theQImageReaderclass 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
QImageWriterclass 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 usesave()orsave()代替。
QMovie
QMovieis a convenience class for displaying animations, using theQImageReaderclass internally. Once created, theQMovieclass provides various functions for both running and controlling the given animation.![]()
QImageReaderandQImageWriterclasses rely on theQImageIOHandlerclass which is the common image I/O interface for all image formats in Qt.QImageIOHandlerobjects are used internally byQImageReaderandQImageWriterto add support for different image formats to Qt.A list of the supported file formats are available through the
supportedImageFormats()andsupportedImageFormats()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 theQImageReaderandQImageWriter类文档编制。Qt’s plugin mechanism can also be used to write a custom image format handler. This is done by deriving from the
QImageIOHandlerclass, and creating aQImageIOPluginobject which is a factory for creatingQImageIOHandlerobjects. When the plugin is installed,QImageReaderandQImageWriterwill automatically load the plugin and start using it.