Qt 4.8
|
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt. More...
#include <qimageiohandler.h>
Public Types | |
enum | ImageOption { Size, ClipRect, Description, ScaledClipRect, ScaledSize, CompressionRatio, Gamma, Quality, Name, SubType, IncrementalReading, Endianness, Animation, BackgroundColor, ImageFormat } |
This enum describes the different options supported by QImageIOHandler. More... | |
Public Functions | |
virtual bool | canRead () const =0 |
Returns true if an image can be read from the device (i. More... | |
virtual int | currentImageNumber () const |
For image formats that support animation, this function returns the sequence number of the current image in the animation. More... | |
virtual QRect | currentImageRect () const |
Returns the rect of the current image. More... | |
QIODevice * | device () const |
Returns the device currently assigned to the QImageIOHandler. More... | |
QByteArray | format () const |
Returns the format that is currently assigned to QImageIOHandler. More... | |
virtual int | imageCount () const |
For image formats that support animation, this function returns the number of images in the animation. More... | |
virtual bool | jumpToImage (int imageNumber) |
For image formats that support animation, this function jumps to the image whose sequence number is imageNumber. More... | |
virtual bool | jumpToNextImage () |
For image formats that support animation, this function jumps to the next image. More... | |
virtual int | loopCount () const |
For image formats that support animation, this function returns the number of times the animation should loop. More... | |
virtual QByteArray | name () const |
Use format() instead. More... | |
virtual int | nextImageDelay () const |
For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image. More... | |
virtual QVariant | option (ImageOption option) const |
Returns the value assigned to option as a QVariant. More... | |
QImageIOHandler () | |
Constructs a QImageIOHandler object. More... | |
virtual bool | read (QImage *image)=0 |
Read an image from the device, and stores it in image. More... | |
void | setDevice (QIODevice *device) |
Sets the device of the QImageIOHandler to device. More... | |
void | setFormat (const QByteArray &format) |
Sets the format of the QImageIOHandler to format. More... | |
void | setFormat (const QByteArray &format) const |
Sets the format of the QImageIOHandler to format. More... | |
virtual void | setOption (ImageOption option, const QVariant &value) |
Sets the option option with the value value. More... | |
virtual bool | supportsOption (ImageOption option) const |
Returns true if the QImageIOHandler supports the option option; otherwise returns false. More... | |
virtual bool | write (const QImage &image) |
Writes the image image to the assigned device. More... | |
virtual | ~QImageIOHandler () |
Destructs the QImageIOHandler object. More... | |
Protected Functions | |
QImageIOHandler (QImageIOHandlerPrivate &dd) | |
Constructs a QImageIOHandler object, using the private member dd. More... | |
Protected Variables | |
QScopedPointer< QImageIOHandlerPrivate > | d_ptr |
The QImageIOHandler class defines the common image I/O interface for all image formats in Qt.
Qt uses QImageIOHandler for reading and writing images through QImageReader and QImageWriter. You can also derive from this class to write your own image format handler using Qt's plugin mechanism.
Call 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() returns true if an image can be read from the device, and read() and 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() and currentImageNumber().
In order to determine what options an image handler supports, Qt will call supportsOption() and setOption(). Make sure to reimplement these functions if you can provide support for any of the options in the ImageOption enum.
To write your own image handler, you must at least reimplement canRead() and read(). Then create a QImageIOPlugin that can create the handler. Finally, install your plugin, and QImageReader and QImageWriter will then automatically load the plugin, and start using it.
Definition at line 61 of file qimageiohandler.h.
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.
Enumerator | |
---|---|
Size | |
ClipRect | |
Description | |
ScaledClipRect | |
ScaledSize | |
CompressionRatio | |
Gamma | |
Quality | |
Name | |
SubType | |
IncrementalReading | |
Endianness | |
Animation | |
BackgroundColor | |
ImageFormat |
Definition at line 81 of file qimageiohandler.h.
QImageIOHandler::QImageIOHandler | ( | ) |
Constructs a QImageIOHandler object.
Definition at line 268 of file qimageiohandler.cpp.
|
virtual |
Destructs the QImageIOHandler object.
Definition at line 289 of file qimageiohandler.cpp.
|
protected |
Constructs a QImageIOHandler object, using the private member dd.
Definition at line 281 of file qimageiohandler.cpp.
|
pure virtual |
Returns 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()).
Implemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QSvgIOHandler, QMngHandler, QJpegHandler, QTgaHandler, QtIcoHandler, and QTiffHandler.
Referenced by QImageReader::canRead(), QImageReader::format(), imageCount(), and QImageReader::imageFormat().
|
virtual |
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.
Reimplemented in QGifHandler, and QMngHandler.
Definition at line 465 of file qimageiohandler.cpp.
Referenced by QImageReader::currentImageNumber().
|
virtual |
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.
Definition at line 477 of file qimageiohandler.cpp.
Referenced by QImageReader::currentImageRect().
QIODevice * QImageIOHandler::device | ( | ) | const |
Returns the device currently assigned to the QImageIOHandler.
If not device has been assigned, 0 is returned.
Definition at line 314 of file qimageiohandler.cpp.
Referenced by QTiffHandler::canRead(), QtIcoHandler::canRead(), QTgaHandler::canRead(), QJpegHandler::canRead(), QMngHandler::canRead(), QSvgIOHandler::canRead(), QXbmHandler::canRead(), QXpmHandler::canRead(), QPpmHandler::canRead(), QPngHandler::canRead(), QBmpHandler::canRead(), iod_read_fn(), QTiffHandler::option(), QSvgIOHandler::option(), QJpegHandler::option(), QtIcoHandler::option(), QSvgIOHandler::read(), QXbmHandler::read(), QPpmHandler::read(), QBmpHandler::read(), QXbmHandler::readHeader(), QXpmHandler::readHeader(), QPpmHandler::readHeader(), QBmpHandler::readHeader(), QXpmHandler::readImage(), setDevice(), QTiffHandler::write(), QtIcoHandler::write(), QJpegHandler::write(), QXbmHandler::write(), QXpmHandler::write(), QPpmHandler::write(), QPngHandler::write(), and QBmpHandler::write().
QByteArray QImageIOHandler::format | ( | ) | const |
Returns the format that is currently assigned to QImageIOHandler.
If no format has been assigned, an empty string is returned.
Definition at line 353 of file qimageiohandler.cpp.
Referenced by QImageReader::format(), QImageReader::imageFormat(), QSvgIOHandlerPrivate::load(), name(), QPpmHandler::option(), QBmpHandler::option(), and setFormat().
|
virtual |
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.
The default implementation returns 1 if canRead() returns true; otherwise 0 is returned.
Reimplemented in QGifHandler, QMngHandler, and QtIcoHandler.
Definition at line 491 of file qimageiohandler.cpp.
Referenced by QImageReader::imageCount().
|
virtual |
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.
The default implementation does nothing, and returns false.
Reimplemented in QMngHandler, and QtIcoHandler.
Definition at line 514 of file qimageiohandler.cpp.
Referenced by QImageReader::jumpToImage().
|
virtual |
For image formats that support animation, this function jumps to the next image.
The default implementation does nothing, and returns false.
Reimplemented in QMngHandler, and QtIcoHandler.
Definition at line 502 of file qimageiohandler.cpp.
Referenced by QImageReader::jumpToNextImage().
|
virtual |
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.
Reimplemented in QGifHandler, and QMngHandler.
Definition at line 525 of file qimageiohandler.cpp.
Referenced by QImageReader::loopCount().
|
virtual |
Use format() instead.
Reimplemented in QBmpHandler, QPngHandler, QXpmHandler, QPpmHandler, QXbmHandler, QGifHandler, QSvgIOHandler, QJpegHandler, QMngHandler, QTgaHandler, QtIcoHandler, and QTiffHandler.
Definition at line 400 of file qimageiohandler.cpp.
|
virtual |
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.
Reimplemented in QGifHandler, and QMngHandler.
Definition at line 536 of file qimageiohandler.cpp.
Referenced by QImageReader::nextImageDelay().
|
virtual |
Returns the value assigned to option as a QVariant.
The type of the value depends on the option. For example, option(Size) returns a QSize variant.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QMngHandler, QGifHandler, QtIcoHandler, QJpegHandler, QSvgIOHandler, QTgaHandler, and QTiffHandler.
Definition at line 435 of file qimageiohandler.cpp.
Referenced by QImageReader::backgroundColor(), QImageReaderPrivate::getText(), QImageReader::imageFormat(), QImageReader::size(), and QImageReader::supportsAnimation().
|
pure virtual |
Read an image from the device, and stores it in image.
Returns 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.
Implemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QSvgIOHandler, QMngHandler, QJpegHandler, QTgaHandler, QtIcoHandler, and QTiffHandler.
Referenced by QImageReader::read().
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 subclass.
Definition at line 304 of file qimageiohandler.cpp.
Referenced by QTiffPlugin::create(), QJpegPlugin::create(), QTgaPlugin::create(), QSvgPlugin::create(), QMngPlugin::create(), QGifPlugin::create(), createReadHandlerHelper(), and if().
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.
Definition at line 326 of file qimageiohandler.cpp.
Referenced by QTiffHandler::canRead(), QTgaHandler::canRead(), QJpegHandler::canRead(), QMngHandler::canRead(), QSvgIOHandler::canRead(), QXbmHandler::canRead(), QXpmHandler::canRead(), QPpmHandler::canRead(), QPngHandler::canRead(), QBmpHandler::canRead(), QTiffPlugin::create(), QTgaPlugin::create(), QICOPlugin::create(), QJpegPlugin::create(), QSvgPlugin::create(), QGifPlugin::create(), QMngPlugin::create(), createReadHandlerHelper(), and if().
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().
Definition at line 340 of file qimageiohandler.cpp.
|
virtual |
Sets the option option with the value value.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QMngHandler, QGifHandler, QJpegHandler, QSvgIOHandler, QTgaHandler, and QTiffHandler.
Definition at line 422 of file qimageiohandler.cpp.
Referenced by createReadHandlerHelper(), if(), QImageReader::read(), QImageReader::setBackgroundColor(), and QImageWriter::write().
|
virtual |
Returns true if the QImageIOHandler supports the option option; otherwise returns false.
For example, if the QImageIOHandler supports the Size option, supportsOption(Size) must return true.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QMngHandler, QGifHandler, QJpegHandler, QSvgIOHandler, QtIcoHandler, QTgaHandler, and QTiffHandler.
Definition at line 449 of file qimageiohandler.cpp.
Referenced by QImageReader::backgroundColor(), QImageReaderPrivate::getText(), QImageReader::imageFormat(), QImageReader::read(), QImageReader::setBackgroundColor(), QImageReader::size(), QImageReader::supportsAnimation(), QImageWriter::supportsOption(), QImageReader::supportsOption(), and QImageWriter::write().
|
virtual |
Writes the image image to the assigned device.
Returns true on success; otherwise returns false.
The default implementation does nothing, and simply returns false.
Reimplemented in QBmpHandler, QPngHandler, QPpmHandler, QXbmHandler, QXpmHandler, QGifHandler, QMngHandler, QJpegHandler, QtIcoHandler, and QTiffHandler.
Definition at line 411 of file qimageiohandler.cpp.
Referenced by QImageWriter::write().
|
protected |
Definition at line 113 of file qimageiohandler.h.