|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.gui.QImageWriter
public class QImageWriter
The QImageWriter
class provides a format independent interface for writing images to files or other devices. QImageWriter
supports setting format specific options, such as the gamma level, compression level and quality, prior to storing the image. If you do not need such options, you can use QImage::save()
or QPixmap::save()
instead.
To store an image, you start by constructing a QImageWriter
object. Pass either a file name or a device pointer, and the image format to QImageWriter
's constructor. You can then set several options, such as the gamma level (by calling setGamma()
) and quality (by calling setQuality()
). canWrite()
returns true if QImageWriter
can write the image (i.e., the image format is supported and the device is open for writing). Call write()
to write the image to the device.
If any error occurs when writing the image, write()
will return false. 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 QImageWriter
can write. QImageWriter
supports all built-in image formats, in addition to any image format plugins that support writing.
QImageReader
, QImageIOHandler
, and QImageIOPlugin
.
Nested Class Summary | |
---|---|
static class |
QImageWriter.ImageWriterError
This enum describes errors that can occur when writing images with QImageWriter . |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.AbstractSignal, 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 | |
---|---|
QImageWriter()
Constructs an empty QImageWriter object. |
|
QImageWriter(QIODevice device,
QByteArray format)
Constructs a QImageWriter object using the device device and image format format. |
|
QImageWriter(java.lang.String fileName)
Constructs a QImageWriter objects that will write to a file with the name fileName, using the image format format. |
|
QImageWriter(java.lang.String fileName,
QByteArray format)
Constructs a QImageWriter objects that will write to a file with the name fileName, using the image format format. |
Method Summary | |
---|---|
boolean |
canWrite()
Returns true if QImageWriter can write the image; i.e., the image format is supported and the assigned device is open for reading. |
int |
compression()
Returns the compression of the image. |
QIODevice |
device()
Returns the device currently assigned to QImageWriter , or 0 if no device has been assigned. |
QImageWriter.ImageWriterError |
error()
Returns the type of error that last occurred. |
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 QImageWriter writes to. |
QByteArray |
format()
Returns the format QImageWriter uses for writing images. |
float |
gamma()
Returns the gamma level of the image. |
int |
quality()
Returns the quality level of the image. |
void |
setCompression(int compression)
This is an image format specific function that set the compression of an image. |
void |
setDevice(QIODevice device)
Sets QImageWriter 's device to device. |
void |
setFileName(java.lang.String fileName)
Sets the file name of QImageWriter to fileName. |
void |
setFormat(QByteArray format)
Sets the format QImageWriter will use when writing images, to format. |
void |
setGamma(float gamma)
This is an image format specific function that sets the gamma level of the image to gamma. |
void |
setQuality(int quality)
This is an image format specific function that sets the quality level of the image to quality. |
void |
setText(java.lang.String key,
java.lang.String text)
Sets the image text associated with the key key to text. |
static java.util.List |
supportedImageFormats()
Returns the list of image formats supported by QImageWriter . |
boolean |
supportsOption(QImageIOHandler.ImageOption option)
Returns true if the writer supports option; otherwise returns false. |
boolean |
write(QImage image)
Writes the image image to the assigned device or file name. |
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 |
---|
public QImageWriter()
QImageWriter
object. Before writing, you must call setFormat()
to set an image format, then setDevice()
or setFileName()
.
public QImageWriter(QIODevice device, QByteArray format)
QImageWriter
object using the device device and image format format.
public QImageWriter(java.lang.String fileName)
QImageWriter
objects that will write to a file with the name fileName, using the image format format. If format is not provided, QImageWriter
will detect the image format by inspecting the extension of fileName.
public QImageWriter(java.lang.String fileName, QByteArray format)
QImageWriter
objects that will write to a file with the name fileName, using the image format format. If format is not provided, QImageWriter
will detect the image format by inspecting the extension of fileName.
Method Detail |
---|
public final boolean canWrite()
QImageWriter
can write the image; i.e., the image format is supported and the assigned device is open for reading. write()
, setDevice()
, and setFormat()
.
public final int compression()
setCompression()
.
public final QIODevice device()
QImageWriter
, or 0 if no device has been assigned. setDevice()
.
public final QImageWriter.ImageWriterError error()
ImageWriterError
, 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 QImageWriter
writes to. 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()
QImageWriter
uses for writing images. setFormat()
.
public final float gamma()
setGamma()
.
public final int quality()
setQuality()
.
public final void setCompression(int compression)
The value range of compression depends on the image format. For example, the "tiff" format supports two values, 0(no compression) and 1(LZW-compression).
compression()
.
public final void setDevice(QIODevice device)
QImageWriter
's device to device. If a device has already been set, the old device is removed from QImageWriter
and is otherwise left unchanged. If the device is not already open, QImageWriter
will attempt to open the device in QIODevice::WriteOnly
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)
QImageWriter
to fileName. Internally, QImageWriter
will create a QFile
and open it in QIODevice::WriteOnly
mode, and use this file when writing images. fileName()
, and setDevice()
.
public final void setFormat(QByteArray format)
QImageWriter
will use when writing images, to format. format is a case insensitive text string. Example: QImageWriter writer = new QImageWriter(); writer.setFormat(new QByteArray("png")); // same as writer.setFormat("PNG");You can call
supportedImageFormats()
for the full list of formats QImageWriter
supports. format()
.
public final void setGamma(float gamma)
The value range of gamma depends on the image format. For example, the "png" format supports a gamma range from 0.0 to 1.0.
gamma()
, and quality()
.
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 setText(java.lang.String key, java.lang.String text)
QImage image = new QImage("some/image.jpeg"); QImageWriter writer = new QImageWriter("images/outimage.png", new QByteArray("png")); writer.setText("Author", "John Smith"); writer.write(image);If you want to store a single block of data (e.g., a comment), you can pass an empty key, or use a generic key like "Description".
The key and text will be embedded into the image data after calling write()
.
Support for this option is implemented through QImageIOHandler::Description
.
QImage::setText()
, and QImageReader::text()
.
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()).
QImageWriter writer = new QImageWriter(fileName); if (writer.supportsOption(QImageIOHandler.ImageOption.Description)) writer.setText("Author", "John Smith");Options can be tested after the writer has been associated with a format.
QImageReader::supportsOption()
, and setFormat()
.
public final boolean write(QImage image)
error()
to find the type of error that occurred, or errorString()
to get a human readable description of the error. canWrite()
, error()
, and errorString()
.
public static java.util.List supportedImageFormats()
QImageWriter
. By default, Qt can write the following formats:
BMP | Windows Bitmap |
JPG | Joint Photographic Experts Group |
JPEG | Joint Photographic Experts Group |
PNG | Portable Network Graphics |
PPM | Portable Pixmap |
TIFF | Tagged Image File Format |
XBM | X11 Bitmap |
XPM | X11 Pixmap |
setFormat()
, QImageReader::supportedImageFormats()
, and QImageIOPlugin
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |