QImageIOHandler 類

The QImageIOHandler 類定義 Qt 中所有圖像格式的公共圖像 I/O 接口。 更多...

頭: #include <QImageIOHandler>
qmake: QT += gui

注意: 此類的所有函數 可重入 .

公共類型

enum ImageOption { Size, ClipRect, ScaledSize, ScaledClipRect, ..., TransformedByDefault }
enum 變換 { TransformationNone, TransformationMirror, TransformationFlip, TransformationRotate180, ..., TransformationRotate270 }
flags 變換

公共函數

QImageIOHandler ()
virtual ~QImageIOHandler ()
virtual bool canRead () const = 0
virtual int currentImageNumber () const
virtual QRect currentImageRect () const
QIODevice * device () const
QByteArray format () const
virtual int imageCount () const
virtual bool jumpToImage (int imageNumber )
virtual bool jumpToNextImage ()
virtual int loopCount () const
virtual int nextImageDelay () const
virtual QVariant option (QImageIOHandler::ImageOption option ) const
virtual bool read (QImage * image ) = 0
void setDevice (QIODevice * device )
void setFormat (const QByteArray & format )
void setFormat (const QByteArray & format ) const
virtual void setOption (QImageIOHandler::ImageOption option , const QVariant & value )
virtual bool supportsOption (QImageIOHandler::ImageOption option ) const
virtual bool write (const QImage & image )

保護變量

QScopedPointer<QImageIOHandlerPrivate> d_ptr

詳細描述

The QImageIOHandler 類定義 Qt 中所有圖像格式的公共圖像 I/O 接口。

Qt 使用 QImageIOHandler 為讀取和寫入圖像透過 QImageReader and QImageWriter 。還可以派生自此類,以使用 Qt 插件機製編寫自己的圖像格式處理程序。

調用 setDevice () to assign a device to the handler, and setFormat () to assign a format to it. One QImageIOHandler may support more than one image format. canRead () 返迴 true if an image can be read from the device, and read () 和 write () return true if reading or writing an image was completed successfully.

QImageIOHandler also has support for animations formats, through the functions loopCount (), imageCount (), nextImageDelay () 和 currentImageNumber ().

In order to determine what options an image handler supports, Qt will call supportsOption () 和 setOption (). Make sure to reimplement these functions if you can provide support for any of the options in the ImageOption 枚舉。

要編寫自己的圖像處理程序,至少必須重實現 canRead () 和 read ()。然後創建 QImageIOPlugin that can create the handler. Finally, install your plugin, and QImageReader and QImageWriter will then automatically load the plugin, and start using it.

另請參閱 QImageIOPlugin , QImageReader ,和 QImageWriter .

成員類型文檔編製

enum QImageIOHandler:: ImageOption

This enum describes the different options supported by QImageIOHandler . Some options are used to query an image for properties, and others are used to toggle the way in which an image should be written.

常量 描述
QImageIOHandler::Size 0 The original size of an image. A handler that supports this option is expected to read the size of the image from the image metadata, and return this size from option () as a QSize .
QImageIOHandler::ClipRect 1 The clip rect, or ROI (Region Of Interest). A handler that supports this option is expected to only read the provided QRect area from the original image in read (), before any other transformation is applied.
QImageIOHandler::ScaledSize 4 The scaled size of the image. A handler that supports this option is expected to scale the image to the provided size (a QSize ), after applying any clip rect transformation (ClipRect). If the handler does not support this option, QImageReader will perform the scaling after the image has been read.
QImageIOHandler::ScaledClipRect 3 The scaled clip rect (or ROI, Region Of Interest) of the image. A handler that supports this option is expected to apply the provided clip rect (a QRect ), after applying any scaling (ScaleSize) or regular clipping (ClipRect). If the handler does not support this option, QImageReader will apply the scaled clip rect after the image has been read.
QImageIOHandler::Description 2 The image description. Some image formats, such as GIF and PNG, allow embedding of text or comments into the image data (e.g., for storing copyright information). It's common that the text is stored in key-value pairs, but some formats store all text in one continuous block. QImageIOHandler returns the text as one QString , where keys and values are separated by a ':', and keys-value pairs are separated by two newlines (\n\n). For example, "Title: Sunset\n\nAuthor: Jim Smith\nSarah Jones\n\n". Formats that store text in a single block can use "Description" as the key.
QImageIOHandler::CompressionRatio 5 The compression ratio of the image data. A handler that supports this option is expected to set its compression rate depending on the value of this option (an int) when writing.
QImageIOHandler::Gamma 6 The gamma level of the image. A handler that supports this option is expected to set the image gamma level depending on the value of this option (a float) when writing.
QImageIOHandler::Quality 7 The quality level of the image. A handler that supports this option is expected to set the image quality level depending on the value of this option (an int) when writing.
QImageIOHandler::Name 8 The name of the image. A handler that supports this option is expected to read the name from the image metadata and return this as a QString , or when writing an image it is expected to store the name in the image metadata.
QImageIOHandler::SubType 9 The subtype of the image. A handler that supports this option can use the subtype value to help when reading and writing images. For example, a PPM handler may have a subtype value of "ppm" or "ppmraw".
QImageIOHandler::IncrementalReading 10 A handler that supports this option is expected to read the image in several passes, as if it was an animation. QImageReader will treat the image as an animation.
QImageIOHandler::Endianness 11 The endianness of the image. Certain image formats can be stored as BigEndian or LittleEndian. A handler that supports Endianness uses the value of this option to determine how the image should be stored.
QImageIOHandler::Animation 12 Image formats that support animation return true for this value in supportsOption (); otherwise, false is returned.
QImageIOHandler::BackgroundColor 13 Certain image formats allow the background color to be specified. A handler that supports BackgroundColor initializes the background color to this option (a QColor ) when reading an image.
QImageIOHandler::ImageFormat 14 The image's data format returned by the handler. This can be any of the formats listed in QImage::Format .
QImageIOHandler::SupportedSubTypes 15 Image formats that support different saving variants should return a list of supported variant names ( QList < QByteArray >) in this option.
QImageIOHandler::OptimizedWrite 16 . A handler which supports this option is expected to turn on optimization flags when writing.
QImageIOHandler::ProgressiveScanWrite 17 . A handler which supports this option is expected to write the image as a progressive scan image.
QImageIOHandler::ImageTransformation 18 . A handler which supports this option can read the transformation metadata of an image. A handler that supports this option should not apply the transformation itself.
QImageIOHandler::TransformedByDefault 19 . A handler that reports support for this feature will have image transformation metadata applied by default on read.

enum QImageIOHandler:: 變換
flags QImageIOHandler:: 變換

This enum describes the different transformations or orientations supported by some image formats, usually through EXIF.

常量 描述
QImageIOHandler::TransformationNone 0 No transformation should be applied.
QImageIOHandler::TransformationMirror 1 Mirror the image horizontally.
QImageIOHandler::TransformationFlip 2 Mirror the image vertically.
QImageIOHandler::TransformationRotate180 TransformationMirror | TransformationFlip Rotate the image 180 degrees. This is the same as mirroring it both horizontally and vertically.
QImageIOHandler::TransformationRotate90 4 將圖像鏇轉 90 度。
QImageIOHandler::TransformationMirrorAndRotate90 TransformationMirror | TransformationRotate90 Mirror the image horizontally and then rotate it 90 degrees.
QImageIOHandler::TransformationFlipAndRotate90 TransformationFlip | TransformationRotate90 Mirror the image vertically and then rotate it 90 degrees.
QImageIOHandler::TransformationRotate270 TransformationRotate180 | TransformationRotate90 Rotate the image 270 degrees. This is the same as mirroring it both horizontally, vertically and then rotating it 90 degrees.

該枚舉在 Qt 5.5 引入或被修改。

Transformations 類型是 typedef 對於 QFlags <Transformation>. It stores an OR combination of Transformation values.

另請參閱 QImageReader::transformation (), QImageReader::setAutoTransform (),和 QImageWriter::setTransformation ().

成員函數文檔編製

QImageIOHandler:: QImageIOHandler ()

構造 QImageIOHandler 對象。

[虛擬] QImageIOHandler:: ~QImageIOHandler ()

銷毀 QImageIOHandler 對象。

[pure virtual] bool QImageIOHandler:: canRead () const

返迴 true if an image can be read from the device (i.e., the image format is supported, the device can be read from and the initial header information suggests that the image can be read); otherwise returns false .

When reimplementing canRead(), make sure that the I/O device ( device ()) is left in its original state (e.g., by using peek() rather than read ()).

另請參閱 read () 和 QIODevice::peek ().

[虛擬] int QImageIOHandler:: currentImageNumber () const

For image formats that support animation, this function returns the sequence number of the current image in the animation. If this function is called before any image is read (), -1 is returned. The number of the first image in the sequence is 0.

If the image format does not support animation, 0 is returned.

另請參閱 read ().

[虛擬] QRect QImageIOHandler:: currentImageRect () const

Returns the rect of the current image. If no rect is defined for the image, and empty QRect() is returned.

This function is useful for animations, where only parts of the frame may be updated at a time.

QIODevice *QImageIOHandler:: device () const

Returns the device currently assigned to the QImageIOHandler . If not device has been assigned, 0 is returned.

另請參閱 setDevice ().

QByteArray QImageIOHandler:: format () const

Returns the format that is currently assigned to QImageIOHandler . If no format has been assigned, an empty string is returned.

另請參閱 setFormat ().

[虛擬] int QImageIOHandler:: imageCount () const

For image formats that support animation, this function returns the number of images in the animation. If the image format does not support animation, or if it is unable to determine the number of images, 0 is returned.

默認實現返迴 1 若 canRead () 返迴 true ;否則返迴 0。

[虛擬] bool QImageIOHandler:: jumpToImage ( int imageNumber )

For image formats that support animation, this function jumps to the image whose sequence number is imageNumber . The next call to read () will attempt to read this image.

默認實現什麼都不做,並返迴 false .

[虛擬] bool QImageIOHandler:: jumpToNextImage ()

For image formats that support animation, this function jumps to the next image.

默認實現什麼都不做,並返迴 false .

[虛擬] int QImageIOHandler:: loopCount () const

For image formats that support animation, this function returns the number of times the animation should loop. If the image format does not support animation, 0 is returned.

[虛擬] int QImageIOHandler:: nextImageDelay () const

For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. If the image format does not support animation, 0 is returned.

[虛擬] QVariant QImageIOHandler:: option ( QImageIOHandler::ImageOption option ) const

Returns the value assigned to option 作為 QVariant . The type of the value depends on the option. For example, option(Size) returns a QSize variant.

另請參閱 setOption () 和 supportsOption ().

[pure virtual] bool QImageIOHandler:: read ( QImage * image )

Read an image from the device, and stores it in image 。返迴 true if the image is successfully read; otherwise returns false.

For image formats that support incremental loading, and for animation formats, the image handler can assume that image points to the previous frame.

另請參閱 canRead ().

void QImageIOHandler:: setDevice ( QIODevice * device )

Sets the device of the QImageIOHandler to device . The image handler will use this device when reading and writing images.

The device can only be set once and must be set before calling canRead (), read (), write (), etc. If you need to read multiple files, construct multiple instances of the appropriate QImageIOHandler 子類。

另請參閱 device ().

void QImageIOHandler:: setFormat (const QByteArray & format )

Sets the format of the QImageIOHandler to format . The format is most useful for handlers that support multiple image formats.

另請參閱 format ().

void QImageIOHandler:: setFormat (const QByteArray & format ) const

Sets the format of the QImageIOHandler to format . The format is most useful for handlers that support multiple image formats.

This function is declared const so that it can be called from canRead ().

另請參閱 format ().

[虛擬] void QImageIOHandler:: setOption ( QImageIOHandler::ImageOption option , const QVariant & value )

設置選項 option 采用值 value .

另請參閱 option () 和 ImageOption .

[虛擬] bool QImageIOHandler:: supportsOption ( QImageIOHandler::ImageOption option ) const

返迴 true QImageIOHandler 支持選項 option ;否則返迴 false 。例如,若 QImageIOHandler 支持 Size 選項,supportsOption(Size) 必須返迴 true。

另請參閱 setOption () 和 option ().

[虛擬] bool QImageIOHandler:: write (const QImage & image )

寫入圖像 image 到賦值設備。返迴 true 當成功時;否則返迴 false .

默認實現什麼都不做,且僅返迴 false .