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  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QImageIO Class Reference


The QImageIO class contains parameters for loading and saving images. More...

#include <qimage.h>

List of all member functions.

Public Members

  • QImageIO () 
  • QImageIO ( QIODevice * ioDevice, const char * format ) 
  • QImageIO ( const QString & fileName, const char * format ) 
  • ~QImageIO () 
  • const QImage& image () const
  • int status () const
  • const char* format () const
  • QIODevice* ioDevice () const
  • QString fileName () const
  • const char* parameters () const
  • QString description () const
  • void setImage ( const QImage & ) 
  • void setStatus ( int ) 
  • void setFormat ( const char * ) 
  • void setIODevice ( QIODevice * ) 
  • void setFileName ( const QString & ) 
  • void setParameters ( const char * ) 
  • void setDescription ( const QString & ) 
  • bool read () 
  • bool write () 

Static Public Members

  • const char* imageFormat ( const QString & fileName ) 
  • const char* imageFormat ( QIODevice * ) 
  • QStrList inputFormats () 
  • QStrList outputFormats () 
  • void defineIOHandler ( const char * format, const char * header, const char * flags, image_io_handler read_image, image_io_handler write_image ) 

Detailed Description

The QImageIO class contains parameters for loading and saving images.

QImageIO contains a QIODevice object that is used for image data I/O. The programmer can install new image file formats in addition to those that Qt implements.

Qt currently supports the following image file formats: PNG, BMP, XBM, XPM and PNM. It may also support JPEG, MNG and GIF, if specially configured during compilation. The different PNM formats are: PBM (P1 or P4), PGM (P2 or P5), PPM (P3 or P6).

You will normally not need to use this class, QPixmap::load(), QPixmap::save() and QImage contain most of the needed functionality.

For image files which contain sequences of images, only the first is read. See the QMovie for loading multiple images.

PBM, PGM, and PPM format output is always in the more condensed raw format. PPM and PGM files with more than 256 levels of intensity are scaled down when reading.

Warning: Unisys has changed its position regarding GIF. If you are in a country where Unisys holds a patent on LZW compression and/or decompression and you want to use GIF, Unisys may require you to license that technology. These countries include Canada, Japan, the USA, France, Germany, Italy and the UK.

GIF support may be removed completely in a future version of Qt. We recommend using the PNG format.

See also QImage, QPixmap, QFile and QMovie.


Member Function Documentation

QImageIO::QImageIO ()

Constructs a QImageIO object with all parameters set to zero.

QImageIO::QImageIO ( QIODevice * ioDevice, const char * format )

Constructs a QImageIO object with an I/O device and a format tag.

QImageIO::QImageIO ( const QString & fileName, const char * format )

Constructs a QImageIO object with a file name and a format tag.

QImageIO::~QImageIO ()

Destructs the object and all related data.

void QImageIO::defineIOHandler ( const char * format, const char * header, const char * flags, image_io_handler read_image, image_io_handler write_image ) [static]

Defines a image IO handler for a specified image format. An image IO handler is responsible for reading and writing images.

Arguments:

  • format is the name of the format.
  • header is a regular expression that recognizes the image header.
  • flags is "T" for text formats like PBM; generally you will want to use 0.
  • read_image is a function to read an image of this format.
  • write_image is a function to write an image of this format.
Both read_image and write_image are of type image_io_handler, which is a function pointer.

Example:

    void readGIF( QImageIO *image )
    {
      // read the image, using the image->ioDevice()
    }

    void writeGIF( QImageIO *image )
    {
      // write the image, using the image->ioDevice()
    }

    // add the GIF image handler

    QImageIO::defineIOHandler( "GIF",
                               "^GIF[0-9][0-9][a-z]",
                               0,
                               readGIF,
                               writeGIF );

Prior to comparison with the regular expression, the file header is converted to change all 0 bytes into 1 bytes. This is done because 0 is such a common header byte yet regular expressions cannot match it.

For image formats supporting incremental display, such as sequences of animated frames, see the QImageFormatType class.

QString QImageIO::description () const

Returns the image description string.

See also setDescription().

QString QImageIO::fileName () const

Returns the file name currently set.

See also setFileName().

const char * QImageIO::format () const

Returns the image format string, or 0 if no format has been explicitly set.

const QImage & QImageIO::image () const

Returns the image currently set.

See also setImage().

const char * QImageIO::imageFormat ( QIODevice * d ) [static]

Returns a string that specifies the image format of the image read from d, or null if the file cannot be read or if the format is not recognized.

const char* QImageIO::imageFormat ( const QString & fileName ) [static]

Returns a string that specifies the image format of the file fileName, or null if the file cannot not be read or if the format is not recognized.

QStrList QImageIO::inputFormats () [static]

Returns a sorted list of image formats which are supported for image input.

QIODevice * QImageIO::ioDevice () const

Returns the IO device currently set.

See also setIODevice().

QStrList QImageIO::outputFormats () [static]

Returns a sorted list of image formats which are supported for image output.

const char * QImageIO::parameters () const

Returns image parameters string.

See also setParameters().

bool QImageIO::read ()

Reads an image into memory and returns TRUE if the image was successfully read.

Before reading an image, you must set an IO device or a file name. If both an IO device and a file name has been set, then the IO device will be used.

Setting the image file format string is optional.

Note that this function does not set the format used to read the image. If you need that information, use the imageFormat() static functions.

Example:

    QImageIO iio;
    QPixmap  pixmap;
    iio.setFileName( "burger.bmp" );
    if ( image.read() )                 // ok
        pixmap = iio.image();           // convert to pixmap

See also setIODevice(), setFileName(), setFormat(), write() and QPixmap::load().

void QImageIO::setDescription ( const QString & description )

Sets the image description string for image handlers that support image descriptions.

Currently, no image format supported by Qt use the description string.

void QImageIO::setFileName ( const QString & fileName )

Sets the name of the file to read or write an image.

See also setIODevice().

void QImageIO::setFormat ( const char * format )

Sets the image format name of the image about to be read or written.

It is necessary to specify a format before writing an image.

It is not necessary to specify a format before reading an image. If not format has been set, Qt guesses the image format before reading it. If a format is set, but the image has another (valid) format, the image will not be read.

See also read(), write() and format().

void QImageIO::setIODevice ( QIODevice * ioDevice )

Sets the IO device to be used for reading or writing an image.

Setting the IO device allows images to be read/written to any block-oriented QIODevice.

If ioDevice is not null, this IO device will override file name settings.

See also setFileName().

void QImageIO::setImage ( const QImage & image )

Sets the image.

See also image().

void QImageIO::setParameters ( const char * parameters )

Sets the image parameters string for image handlers that require special parameters.

Although all image formats supported by Qt ignore the parameters string, it will be useful for future extensions or contributions (like JPEG).

void QImageIO::setStatus ( int status )

Sets the image IO status. A non-zero value indicates an error, while 0 means that the IO operation was successful.

See also status().

int QImageIO::status () const

Returns the image IO status. A non-zero value indicates an error, while 0 means that the IO operation was successful.

See also setStatus().

bool QImageIO::write ()

Writes an image to an IO device and returns TRUE if the image was successfully written.

Before writing an image, you must set an IO device or a file name. If both an IO device and a file name has been set, then the IO device will be used.

The image will be written using the specified image format.

Example:

    QImageIO iio;
    QImage   im;
    im = pixmap;                                // convert to image
    iio.setImage( im );
    iio.setFileName( "burger.bmp" );
    iio.setFormat( "BMP" );
    iio.write();                                // TRUE if ok

See also setIODevice(), setFileName(), setFormat(), read() and QPixmap::save().


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.

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 2.3
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