The QImageWriter 類提供用於將圖像寫入文件 (或其它設備) 的格式獨立接口。 更多...
| 頭: | #include <QImageWriter> |
注意: 此類的所有函數 可重入 .
| enum | ImageWriterError { DeviceError, UnsupportedFormatError, UnknownError } |
| QImageWriter () | |
| QImageWriter (QIODevice * device , const QByteArray & format ) | |
| QImageWriter (const QString & fileName , const QByteArray & format = QByteArray()) | |
| ~QImageWriter () | |
| bool | canWrite () const |
| int | compression () const |
| QIODevice * | device () const |
| ImageWriterError | error () const |
| QString | errorString () const |
| QString | fileName () const |
| QByteArray | format () const |
| float | gamma () const |
| int | quality () const |
| void | setCompression (int compression ) |
| void | setDevice (QIODevice * device ) |
| void | setFileName (const QString & fileName ) |
| void | setFormat (const QByteArray & format ) |
| void | setGamma (float gamma ) |
| void | setQuality (int quality ) |
| void | setText (const QString & key , const QString & text ) |
| bool | supportsOption (QImageIOHandler::ImageOption option ) const |
| bool | write (const QImage & image ) |
| QList<QByteArray> | supportedImageFormats () |
The QImageWriter 類提供用於將圖像寫入文件 (或其它設備) 的格式獨立接口。
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 () 或 QPixmap::save () 代替。
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 () 能將圖像寫入設備。
若齣現任何錯誤當寫入圖像時, write () 將返迴 false。然後,可以調用 error () 以查找齣現的錯誤類型,或 errorString () 以獲得人類可讀的什麼錯誤描述。
調用 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 ,和 QImageIOPlugin .
此枚舉描述可以齣現的錯誤, 當寫入圖像采用 QImageWriter .
| 常量 | 值 | 描述 |
|---|---|---|
QImageWriter::DeviceError
|
1
|
QImageWriter encountered a device error when writing the image data. Consult your device for more details on what went wrong. |
QImageWriter::UnsupportedFormatError
|
2
|
Qt 不支持請求的圖像格式。 |
QImageWriter::UnknownError
|
0
|
An unknown error occurred. If you get this value after calling write (), it is most likely caused by a bug in QImageWriter . |
構造空的 QImageWriter object. Before writing, you must call setFormat () 來設置圖像格式,然後 setDevice () 或 setFileName ().
構造 QImageWriter 對象使用設備 device 和圖像格式 format .
構造 QImageWriter objects that will write to a file with the name fileName ,使用圖像格式 format 。若 format is not provided, QImageWriter will detect the image format by inspecting the extension of fileName .
銷毀 QImageWriter 對象。
返迴 true 若 QImageWriter 可以寫入圖像;即:圖像格式支持且為讀取打開賦值設備。
另請參閱 write (), setDevice (),和 setFormat ().
返迴圖像的壓縮。
另請參閱 setCompression ().
返迴的設備目前被賦值給 QImageWriter , or 0 if no device has been assigned.
另請參閱 setDevice ().
返迴最後發生的錯誤類型。
另請參閱 ImageWriterError and errorString ().
返迴最近發生錯誤的人類可讀描述。
另請參閱 error ().
若目前賦值設備是 QFile ,或者若 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 被返迴。
另請參閱 setFileName () 和 setDevice ().
返迴格式 QImageWriter 用於寫入圖像。
另請參閱 setFormat ().
Returns the gamma level of the image.
另請參閱 setGamma ().
Returns the quality level of the image.
另請參閱 setQuality ().
This is an image format specific function that set the compression of an image. For image formats that do not support setting the compression, this value is ignored.
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 ().
集 QImageWriter 的設備到 device . If a device has already been set, the old device is removed from QImageWriter and is otherwise left unchanged.
若設備尚未打開, 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 () 和 setFileName ().
Sets the file name of QImageWriter to fileName . Internally, QImageWriter 將創建 QFile and open it in QIODevice::WriteOnly mode, and use this file when writing images.
另請參閱 fileName () 和 setDevice ().
設置格式 QImageWriter will use when writing images, to format . format is a case insensitive text string. Example:
QImageWriter writer; writer.setFormat("png"); // same as writer.setFormat("PNG");
可以調用 supportedImageFormats () 瞭解完整格式列錶 QImageWriter 支持。
另請參閱 format ().
This is an image format specific function that sets the gamma level of the image to gamma . For image formats that do not support setting the gamma level, this value is ignored.
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.
This is an image format specific function that sets the quality level of the image to quality . For image formats that do not support setting the quality, this value is ignored.
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 ().
設置圖像文本關聯鍵 key to text . This is useful for storing copyright information or other information about the image. Example:
QImage image("some/image.jpeg"); QImageWriter writer("images/outimage.png", "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 ().
支持此選項的實現是透過 QImageIOHandler::Description .
該函數在 Qt 4.1 引入。
另請參閱 QImage::setText () 和 QImageReader::text ().
[static]
QList
<
QByteArray
> QImageWriter::
supportedImageFormats
()
返迴圖像格式列錶支持通過 QImageWriter .
默認情況下,Qt 可以寫入下列格式:
| 格式 | 描述 |
|---|---|
| BMP | Windows 位圖 |
| JPG | JPEG (聯閤攝影專傢組) |
| JPEG | JPEG (聯閤攝影專傢組) |
| PNG | PNG (便攜式網絡圖形) |
| PPM | Portable Pixmap (便攜式像素圖) |
| TIFF | TIFF (標簽化圖像文件格式) |
| XBM | X11 Bitmap (X11 位圖) |
| XPM | X11 Pixmap (X11 像素圖) |
Reading and writing SVG files is supported through Qt's SVG Module .
注意, QApplication 實例必須被創建在調用此函數之前。
另請參閱 setFormat (), QImageReader::supportedImageFormats (),和 QImageIOPlugin .
Returns true if the writer supports option ;否則返迴 false。
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(fileName); if (writer.supportsOption(QImageIOHandler::Description)) writer.setText("Author", "John Smith");
可以被測試 option,在寫入器已關聯格式後。
該函數在 Qt 4.2 引入。
另請參閱 QImageReader::supportsOption () 和 setFormat ().
寫入圖像 image to the assigned device or file name. Returns true on success; otherwise returns false. If the operation fails, you can call error () 以查找齣現的錯誤類型,或 errorString () 以獲取人類可讀錯誤描述。
另請參閱 canWrite (), error (),和 errorString ().