com.trolltech.qt.gui
Class QImageIOHandler

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.gui.QImageIOHandler
All Implemented Interfaces:
QtJambiInterface

public abstract class QImageIOHandler
extends QtJambiObject

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.

See also:
QImageIOPlugin, QImageReader, and QImageWriter.


Nested Class Summary
static class QImageIOHandler.ImageOption
          This enum describes the different options supported by QImageIOHandler.
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QImageIOHandler()
          Constructs a QImageIOHandler object.
 
Method Summary
abstract  boolean canRead()
          Returns true if an image can be read from the device (i.
 int currentImageNumber()
          For image formats that support animation, this function returns the sequence number of the current image in the animation.
 QRect currentImageRect()
          Returns the rect of the current image.
 QIODevice device()
          Returns the device currently assigned to the QImageIOHandler.
 QByteArray format()
          Returns the format that is currently assigned to QImageIOHandler.
 int imageCount()
          For image formats that support animation, this function returns the number of images in the animation.
 boolean jumpToImage(int imageNumber)
          For image formats that support animation, this function jumps to the image whose sequence number is imageNumber.
 boolean jumpToNextImage()
          For image formats that support animation, this function jumps to the next image.
 int loopCount()
          For image formats that support animation, this function returns the number of times the animation should loop.
 int nextImageDelay()
          For image formats that support animation, this function returns the number of milliseconds to wait until reading the next image.
 java.lang.Object option(QImageIOHandler.ImageOption option)
          Returns the value assigned to option as a QVariant.
abstract  boolean read(QImage image)
          Read an image from the device, and stores it in image.
 void setDevice(QIODevice device)
          Sets the device of the QImageIOHandler to device.
 void setFormat(QByteArray format)
          Sets the format of the QImageIOHandler to format.
 void setOption(QImageIOHandler.ImageOption option, java.lang.Object value)
          Sets the option option with the value value.
 boolean supportsOption(QImageIOHandler.ImageOption option)
          Returns true if the QImageIOHandler supports the option option; otherwise returns false.
 boolean write(QImage image)
          Writes the image image to the assigned device.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QImageIOHandler

public QImageIOHandler()
Constructs a QImageIOHandler object.

Method Detail

device

public final QIODevice device()
Returns the device currently assigned to the QImageIOHandler. If not device has been assigned, 0 is returned.

See also:
setDevice().


format

public final QByteArray format()
Returns the format that is currently assigned to QImageIOHandler. If no format has been assigned, an empty string is returned.

See also:
setFormat().


setDevice

public final void 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.

See also:
device().


setFormat

public final void setFormat(QByteArray format)
Sets the format of the QImageIOHandler to format. The format is most useful for handlers that support multiple image formats.

See also:
format().


canRead

public abstract boolean canRead()
Returns true if an image can be read from the device (i. ., 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()).

See also:
read(), and QIODevice::peek().


currentImageNumber

public int currentImageNumber()
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.

See also:
read().


currentImageRect

public QRect currentImageRect()
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.


imageCount

public int imageCount()
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.


jumpToImage

public boolean 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.

The default implementation does nothing, and returns false.


jumpToNextImage

public boolean jumpToNextImage()
For image formats that support animation, this function jumps to the next image.

The default implementation does nothing, and returns false.


loopCount

public int loopCount()
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.


nextImageDelay

public int nextImageDelay()
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.


option

public java.lang.Object option(QImageIOHandler.ImageOption option)
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.

See also:
setOption(), and supportsOption().


read

public abstract boolean read(QImage image)
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.

See also:
canRead().


setOption

public void setOption(QImageIOHandler.ImageOption option,
                      java.lang.Object value)
Sets the option option with the value value.

See also:
option(), and ImageOption .


supportsOption

public boolean supportsOption(QImageIOHandler.ImageOption option)
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.

See also:
setOption(), and option().


write

public boolean write(QImage image)
Writes the image image to the assigned device. Returns true on success; otherwise returns false.

The default implementation does nothing, and simply returns false.