Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QImageWriter Class Reference
[QtGui module]

The QImageWriter class provides a format independent interface for writing images to files or other devices. More...

#include <QImageWriter>

Note: All the functions in this class are reentrant.

Public Types

Public Functions

Static Public Members


Detailed Description

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.

See also QImageReader, QImageIOHandler, and QImageIOPlugin.


Member Type Documentation

enum QImageWriter::ImageWriterError

This enum describes errors that can occur when writing images with QImageWriter.

ConstantValueDescription
QImageWriter::DeviceError1QImageWriter encountered a device error when writing the image data. Consult your device for more details on what went wrong.
QImageWriter::UnsupportedFormatError2Qt does not support the requested image format.
QImageWriter::UnknownError0An unknown error occurred. If you get this value after calling write(), it is most likely caused by a bug in QImageWriter.


Member Function Documentation

QImageWriter::QImageWriter ()

Constructs an empty QImageWriter object. Before writing, you must call setFormat() to set an image format, then setDevice() or setFileName().

QImageWriter::QImageWriter ( QIODevice * device, const QByteArray & format )

Constructs a QImageWriter object using the device device and image format format.

QImageWriter::QImageWriter ( const QString & fileName, const QByteArray & format = QByteArray() )

Constructs a 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.

QImageWriter::~QImageWriter ()

Destructs the QImageWriter object.

bool QImageWriter::canWrite () const

Returns true if QImageWriter can write the image (i.e., the image format is supported and the assigned device is open for reading.

See also write(), setDevice(), and setFormat().

QIODevice * QImageWriter::device () const

Returns the device currently assigned to QImageWriter, or 0 if no device has been assigned.

See also setDevice().

ImageWriterError QImageWriter::error () const

Returns the type of error that last occurred.

See also ImageWriterError and errorString().

QString QImageWriter::errorString () const

Returns a human readable description of the last error that occurred.

See also error().

QString QImageWriter::fileName () const

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. Otherwise (i.e., if no device has been assigned or the device is not a QFile), an empty QString is returned.

See also setFileName() and setDevice().

QByteArray QImageWriter::format () const

Returns the format QImageWriter uses for writing images.

See also setFormat().

float QImageWriter::gamma () const

Returns the gamma level of the image.

See also setGamma().

int QImageWriter::quality () const

Returns the quality level of the image.

See also setQuality().

void QImageWriter::setDevice ( QIODevice * device )

Sets 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.

See also device() and setFileName().

void QImageWriter::setFileName ( const QString & fileName )

Sets the file name of QImageWriter to fileName. Internally, QImageWriter will create a QFile and open it in QIODevice::WriteOnly mode, and use this file when writing images.

See also fileName() and setDevice().

void QImageWriter::setFormat ( const QByteArray & format )

Sets the format 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");

You can call supportedImageFormats() for the full list of formats QImageWriter supports.

See also format().

void QImageWriter::setGamma ( float gamma )

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.

See also gamma() and quality().

void QImageWriter::setQuality ( int quality )

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).

See also quality().

void QImageWriter::setText ( const QString & key, const QString & text )

Sets the image text associated with the key 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().

Support for this option is implemented through QImageIOHandler::Description.

This function was introduced in Qt 4.1.

See also QImage::setText() and QImageReader::text().

QList<QByteArray> QImageWriter::supportedImageFormats ()   [static]

Returns the list of image formats supported by QImageWriter.

By default, Qt can write the following formats:

FormatDescription
BMPWindows Bitmap
JPGJoint Photographic Experts Group
JPEGJoint Photographic Experts Group
PNGPortable Network Graphics
PPMPortable Pixmap
XBMX11 Bitmap
XPMX11 Pixmap

See also setFormat(), QImageReader::supportedImageFormats(), and QImageIOPlugin.

bool QImageWriter::write ( const QImage & image )

Writes the image image to the assigned device or file name. Returns true on success; otherwise returns false. If the operation fails, you can call error() to find the type of error that occurred, or errorString() to get a human readable description of the error.

See also canWrite(), error(), and errorString().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 53
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  4. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  5. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  6. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  7. La rubrique Qt a besoin de vous ! 1
Page suivante

Le blog Digia au hasard

Logo

Déploiement d'applications Qt Commercial sur les tablettes Windows 8

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.1
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web