QImageIOPlugin 类

QImageIOPlugin 类定义用于编写图像格式插件的接口。 更多...

头: #include <QImageIOPlugin>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QObject

注意: 此类的所有函数 可重入 .

公共类型

flags Capabilities
enum Capability { CanRead, CanWrite, CanReadIncremental }

公共函数

QImageIOPlugin (QObject * parent = nullptr)
virtual ~QImageIOPlugin ()
virtual QImageIOPlugin::Capabilities capabilities (QIODevice * device , const QByteArray & format ) const = 0
virtual QImageIOHandler * create (QIODevice * device , const QByteArray & format = QByteArray()) const = 0

详细描述

QImageIOPlugin is a factory for creating QImageIOHandler objects, which are used internally by QImageReader and QImageWriter to add support for different image formats to Qt.

Writing an image I/O plugin is achieved by subclassing this base class, reimplementing the pure virtual functions capabilities () 和 create (),和导出类采用 Q_PLUGIN_METADATA () macro. See 如何创建 Qt 插件 了解细节。

An image format plugin can support three capabilities: reading ( CanRead ), writing ( CanWrite ) 和 incremental reading ( CanReadIncremental ). Reimplement capabilities () in your subclass to expose the capabilities of your image format.

create () should create an instance of your QImageIOHandler subclass, with the provided device and format properly set, and return this handler.

The json metadata file for the plugin needs to contain information about the image formats the plugins supports, together with the corresponding MIME types (one for each format). For a jpeg plugin, this could, for example, look as follows:

{
  "Keys": [ "jpg", "jpeg" ],
  "MimeTypes": [ "image/jpeg", "image/jpeg" ]
}
					

Different plugins can support different capabilities. For example, you may have one plugin that supports reading the GIF format, and another that supports writing. Qt will select the correct plugin for the job, depending on the return value of capabilities (). If several plugins support the same capability, Qt will select one arbitrarily.

另请参阅 QImageIOHandler and 如何创建 Qt 插件 .

成员类型文档编制

enum QImageIOPlugin:: Capability
flags QImageIOPlugin:: Capabilities

此枚举描述能力为 QImageIOPlugin .

常量 描述
QImageIOPlugin::CanRead 0x1 插件可以读取图像。
QImageIOPlugin::CanWrite 0x2 插件可以写入图像。
QImageIOPlugin::CanReadIncremental 0x4 插件可以增量读取图像。

Capabilities 类型是 typedef 对于 QFlags <Capability>。它存储 Capability 值的 OR 组合。

成员函数文档编制

[explicit] QImageIOPlugin:: QImageIOPlugin ( QObject * parent = nullptr)

构造图像插件采用给定 parent . This is invoked automatically by the moc generated code that exports the plugin.

[virtual noexcept] QImageIOPlugin:: ~QImageIOPlugin ()

销毁图片格式插件。

从不需要明确调用这。Qt 自动销毁插件当不再使用时。

[pure virtual] QImageIOPlugin::Capabilities QImageIOPlugin:: capabilities ( QIODevice * device , const QByteArray & format ) const

Returns the capabilities of the plugin, based on the data in device and the format format 。若 device is 0 , it should simply report whether the format can be read or written. Otherwise, it should attempt to determine whether the given format (or any format supported by the plugin if format is empty) can be read from or written to device . It should do this without changing the state of device (typically by using QIODevice::peek ()).

For example, if the QImageIOPlugin supports the BMP format, format is either empty or "bmp" , and the data in the device starts with the characters "BM" , this function should return CanRead 。若 format is "bmp" , device is 0 and the handler supports both reading and writing, this function should return CanRead | CanWrite .

Format names are always given in lower case.

[pure virtual] QImageIOHandler *QImageIOPlugin:: create ( QIODevice * device , const QByteArray & format = QByteArray()) const

创建并返回 QImageIOHandler subclass, with device and format set. The format must come from the values listed in the "Keys" entry in the plugin metadata, or be empty. If it is empty, the data in device must have been recognized by the capabilities () method (with a likewise empty format).

Format names are always given in lower case.