|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QImageReader
public class QImageReader
The QImageReader
class provides a format independent interface for reading images from files or other devices. The most common way to read images is through QImage
and QPixmap
's constructors, or by calling QImage::load()
and QPixmap::load()
. QImageReader
is a specialized class which gives you more control when reading images. For example, you can read an image into a specific size by calling setScaledSize()
, and you can select a clip rect, effectively loading only parts of an image, by calling setClipRect()
. Depending on the underlying support in the image format, this can save memory and speed up loading of images.
To read an image, you start by constructing a QImageReader
object. Pass either a file name or a device pointer, and the image format to QImageReader
's constructor. You can then set several options, such as the clip rect (by calling setClipRect()
) and scaled size (by calling setScaledSize()
). canRead()
returns the image if the QImageReader
can read the image (i.e., the image format is supported and the device is open for reading). Call read()
to read the image.
If any error occurs when reading the image, read()
will return a null QImage
. You can then call error()
to find the type of error that occurred, or errorString()
to get a human readable description of what went wrong.
Call supportedImageFormats()
for a list of formats that QImageReader
can read. QImageReader
supports all built-in image formats, in addition to any image format plugins that support reading.
QImageWriter
, QImageIOHandler
, and QImageIOPlugin
.
Nested Class Summary | |
---|---|
static class |
QImageReader.ImageReaderError
This enum describes the different types of errors that can occur when reading images with QImageReader . |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Constructor Summary | |
---|---|
QImageReader()
Constructs an empty QImageReader object. |
|
QImageReader(QIODevice device)
Constructs a QImageReader object with the device device and the image format format. |
|
QImageReader(QIODevice device,
QByteArray format)
Constructs a QImageReader object with the device device and the image format format. |
|
QImageReader(java.lang.String fileName)
Constructs a QImageReader object with the file name fileName and the image format format. |
|
QImageReader(java.lang.String fileName,
QByteArray format)
Constructs a QImageReader object with the file name fileName and the image format format. |
Method Summary | |
---|---|
QColor |
backgroundColor()
Returns the background color that's used when reading an image. |
boolean |
canRead()
Returns true if an image can be read for the device (i.e., the image format is supported, and the device seems to contain valid data); otherwise returns false. |
QRect |
clipRect()
Returns the clip rect (also known as the ROI, or Region Of Interest) of the image. |
int |
currentImageNumber()
For image formats that support animation, this function returns the sequence number of the current frame. |
QRect |
currentImageRect()
For image formats that support animation, this function returns the rect for the current frame. |
QIODevice |
device()
Returns the device currently assigned to QImageReader , or 0 if no device has been assigned. |
QImageReader.ImageReaderError |
error()
Returns the type of error that occurred last. |
java.lang.String |
errorString()
Returns a human readable description of the last error that occurred. |
java.lang.String |
fileName()
If the currently assigned device is a QFile , or if setFileName() has been called, this function returns the name of the file QImageReader reads from. |
QByteArray |
format()
Returns the format QImageReader uses for reading images. |
static QImageReader |
fromNativePointer(QNativePointer nativePointer)
|
int |
imageCount()
For image formats that support animation, this function returns the total number of images in the animation. |
static QByteArray |
imageFormat(QIODevice device)
If supported, this function returns the image format of the device device. |
static QByteArray |
imageFormat(java.lang.String fileName)
If supported, this function returns the image format of the file fileName. |
boolean |
jumpToImage(int imageNumber)
For image formats that support animation, this function skips to the image whose sequence number is imageNumber, returning true if successful or false if the corresponding image cannot be found. |
boolean |
jumpToNextImage()
For image formats that support animation, this function steps over the current image, returning true if successful or false if there is no following image in the animation. |
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 displaying the next frame in the animation. |
int |
quality()
Returns the quality level of the image. |
QImage |
read()
Reads an image from the device. |
QRect |
scaledClipRect()
Returns the scaled clip rect of the image. |
QSize |
scaledSize()
Returns the scaled size of the image. |
void |
setBackgroundColor(QColor color)
Sets the background color to color. |
void |
setClipRect(QRect rect)
Sets the image clip rect (also known as the ROI, or Region Of Interest) to rect. |
void |
setDevice(QIODevice device)
Sets QImageReader 's device to device. |
void |
setFileName(java.lang.String fileName)
Sets the file name of QImageReader to fileName. |
void |
setFormat(QByteArray format)
Sets the format QImageReader will use when reading images, to format. |
void |
setQuality(int quality)
This is an image format specific function that sets the quality level of the image to quality. |
void |
setScaledClipRect(QRect rect)
Sets the scaled clip rect to rect. |
void |
setScaledSize(QSize size)
Sets the scaled size of the image to size. |
QSize |
size()
Returns the size of the image, without actually reading the image contents. |
static java.util.List |
supportedImageFormats()
Returns the list of image formats supported by QImageReader . |
boolean |
supportsAnimation()
Returns true if the image format supports animation; otherwise, false is returned. |
boolean |
supportsOption(QImageIOHandler.ImageOption option)
Returns true if the reader supports option; otherwise returns false. |
java.lang.String |
text(java.lang.String key)
Returns the image text associated with key. |
java.util.List |
textKeys()
Returns the text keys for this image. |
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 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 |
---|
public QImageReader()
QImageReader
object. Before reading an image, call setDevice()
or setFileName()
.
public QImageReader(QIODevice device)
QImageReader
object with the device device and the image format format.
public QImageReader(QIODevice device, QByteArray format)
QImageReader
object with the device device and the image format format.
public QImageReader(java.lang.String fileName)
QImageReader
object with the file name fileName and the image format format. setFileName()
.
public QImageReader(java.lang.String fileName, QByteArray format)
QImageReader
object with the file name fileName and the image format format. setFileName()
.
Method Detail |
---|
public final QColor backgroundColor()
setBackgroundColor()
, and read()
.
public final boolean canRead()
canRead()
is a lightweight function that only does a quick test to see if the image data is valid. read()
may still return false after canRead()
returns true, if the image data is corrupt.
For images that support animation, canRead()
returns false when all frames have been read.
read()
, and supportedImageFormats()
.
public final QRect clipRect()
QRect
is returned. setClipRect()
.
public final int currentImageNumber()
supportsAnimation()
, and QImageIOHandler::currentImageNumber()
.
public final QRect currentImageRect()
supportsAnimation()
, and QImageIOHandler::currentImageRect()
.
public final QIODevice device()
QImageReader
, or 0 if no device has been assigned. setDevice()
.
public final QImageReader.ImageReaderError error()
ImageReaderError
, and errorString()
.
public final java.lang.String errorString()
error()
.
public final java.lang.String fileName()
QFile
, or if setFileName()
has been called, this function returns the name of the file QImageReader
reads from. Otherwise (i.e., if no device has been assigned or the device is not a QFile
), an empty QString is returned. setFileName()
, and setDevice()
.
public final QByteArray format()
QImageReader
uses for reading images. You can call this function after assigning a device to the reader to determine the format of the device. For example:
QImageReader reader("image.png"); // reader.format() == "png"If the reader cannot read any image from the device (e.g., there is no image there, or the image has already been read), or if the format is unsupported, this function returns an empty QByteArray().
setFormat()
, and supportedImageFormats()
.
public final int imageCount()
Certain animation formats do not support this feature, in which case 0 is returned.
supportsAnimation()
, and QImageIOHandler::imageCount()
.
public final boolean jumpToImage(int imageNumber)
The next call to read()
will attempt to read this image.
jumpToNextImage()
, and QImageIOHandler::jumpToImage()
.
public final boolean jumpToNextImage()
The default implementation calls read()
, then discards the resulting image, but the image handler may have a more efficient way of implementing this operation.
jumpToImage()
, and QImageIOHandler::jumpToNextImage()
.
public final int loopCount()
supportsAnimation()
, and QImageIOHandler::loopCount()
.
public final int nextImageDelay()
supportsAnimation()
, and QImageIOHandler::nextImageDelay()
.
public final int quality()
setQuality()
.
public final QImage read()
QImage
is returned. You can then call error()
to find the type of error that occurred, or errorString()
to get a human readable description of the error. For image formats that support animation, calling read()
repeatedly will return the next frame. When all frames have been read, a null image will be returned.
canRead()
, supportedImageFormats()
, supportsAnimation()
, and QMovie
.
public final QRect scaledClipRect()
setScaledClipRect()
.
public final QSize scaledSize()
setScaledSize()
.
public final void setBackgroundColor(QColor color)
backgroundColor()
, and read()
.
public final void setClipRect(QRect rect)
size()
. clipRect()
, setScaledSize()
, and setScaledClipRect()
.
public final void setDevice(QIODevice device)
QImageReader
's device to device. If a device has already been set, the old device is removed from QImageReader
and is otherwise left unchanged. If the device is not already open, QImageReader
will attempt to open the device in QIODevice::ReadOnly
mode by calling open()
. Note that this does not work for certain devices, such as QProcess
, QTcpSocket
and QUdpSocket
, where more logic is required to open the device.
device()
, and setFileName()
.
public final void setFileName(java.lang.String fileName)
QImageReader
to fileName. Internally, QImageReader
will create a QFile
object and open it in QIODevice::ReadOnly
mode, and use this when reading images. If fileName does not include a file extension (e.g., .png or .bmp), QImageReader
will cycle through all supported extensions until it finds a matching file.
fileName()
, setDevice()
, and supportedImageFormats()
.
public final void setFormat(QByteArray format)
QImageReader
will use when reading images, to format. format is a case insensitive text string. Example: QImageReader reader; reader.setFormat("png"); // same as reader.setFormat("PNG");You can call
supportedImageFormats()
for the full list of formats QImageReader
supports. format()
.
public final void setQuality(int quality)
The value range of quality depends on the image format. For example, the "jpeg" format supports a quality range from 0 (low quality, high compression) to 100 (high quality, low compression).
quality()
.
public final void setScaledClipRect(QRect rect)
scaledClipRect()
, and setScaledSize()
.
public final void setScaledSize(QSize size)
QImageReader
will use QImage::scale()
with Qt::SmoothScaling
. scaledSize()
, setClipRect()
, and setScaledClipRect()
.
public final QSize size()
If the image format does not support this feature, this function returns an invalid size. Qt's built-in image handlers all support this feature, but custom image format plugins are not required to do so.
QImageIOHandler::ImageOption
, QImageIOHandler::option()
, and QImageIOHandler::supportsOption()
.
public final boolean supportsAnimation()
QMovie::supportedFormats()
.
public final boolean supportsOption(QImageIOHandler.ImageOption option)
Different image formats support different options. Call this function to determine whether a certain option is supported by the current format. For example, the PNG format allows you to embed text into the image's metadata (see text()
), and the BMP format allows you to determine the image's size without loading the whole image into memory (see size()
).
QImageReader reader(":/image.png"); if (reader.supportsOption(QImageIOHandler::Size)) qDebug() << "Size:" << reader.size();
QImageWriter::supportsOption()
.
public final java.lang.String text(java.lang.String key)
Support for this option is implemented through QImageIOHandler::Description
.
textKeys()
, and QImageWriter::setText()
.
public final java.util.List textKeys()
text()
to list the image text for a certain key. Support for this option is implemented through QImageIOHandler::Description
.
text()
, QImageWriter::setText()
, and QImage::textKeys()
.
public static QByteArray imageFormat(QIODevice device)
public static QByteArray imageFormat(java.lang.String fileName)
public static java.util.List supportedImageFormats()
QImageReader
. By default, Qt can read the following formats:
BMP | Windows Bitmap |
GIF | Graphic Interchange Format (optional) |
JPG | Joint Photographic Experts Group |
JPEG | Joint Photographic Experts Group |
MNG | Multiple-image Network Graphics |
PNG | Portable Network Graphics |
PBM | Portable Bitmap |
PGM | Portable Graymap |
PPM | Portable Pixmap |
TIFF | Tagged Image File Format |
XBM | X11 Bitmap |
XPM | X11 Pixmap |
To configure Qt with GIF support, pass -qt-gif to the configure script or check the appropriate option in the graphical installer.
setFormat()
, QImageWriter::supportedImageFormats()
, and QImageIOPlugin
.
public static QImageReader fromNativePointer(QNativePointer nativePointer)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |