Home · All Classes · All Functions · Overviews

[Previous: The Coordinate System] [The Paint System] [Next: Styling]

Reading and Writing Image Files

The most common way to read images is through QImage and QPixmap's constructors, or by calling the QImage::load() and QPixmap::load() functions. In addition, Qt provides the QImageReader class which gives more control over the process. Depending on the underlying support in the image format, the functions provided by the class can save memory and speed up loading of images.

Likewise, Qt provides the QImageWriter class which 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.

QMovie

QMovie is a convenience class for displaying animations, using the QImageReader class internally. Once created, the QMovie class provides various functions for both running and controlling the given animation.

The QImageReader and QImageWriter classes rely on the QImageIOHandler class which is the common image I/O interface for all image formats in Qt. QImageIOHandler objects are used internally by QImageReader and QImageWriter to add support for different image formats to Qt.

A list of the supported file formats are available through the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions. Qt supports several file formats by default, and in addition new formats can be added as plugins. The currently supported formats are listed in the QImageReader and QImageWriter class documentation.

Qt's plugin mechanism can also be used to write a custom image format handler. This is done by deriving from the QImageIOHandler class, and creating a QImageIOPlugin object which is a factory for creating QImageIOHandler objects. When the plugin is installed, QImageReader and QImageWriter will automatically load the plugin and start using it.

Rendering SVG files

SVG Rendering

Scalable Vector Graphics (SVG) is a language for describing two-dimensional graphics and graphical applications in XML. SVG 1.1 is a W3C Recommendation and forms the core of the current SVG developments in Qt. SVG 1.2 is the specification currently being developed by the SVG Working Group, and it is available in draft form. The Mobile SVG Profiles (SVG Basic and SVG Tiny) are aimed at resource-limited devices and are part of the 3GPP platform for third generation mobile phones. You can read more about SVG at About SVG.

Qt supports the static features of SVG 1.2 Tiny. ECMA scripts and DOM manipulation are currently not supported.

SVG drawings can be rendered onto any QPaintDevice subclass. This approach gives developers the flexibility to experiment, in order to find the best solution for each application.

The easiest way to render SVG files is to construct a QSvgWidget and load an SVG file using one of the QSvgWidget::load() functions.

QSvgRenderer is the class responsible for rendering SVG files for QSvgWidget, and it can be used directly to provide SVG support for custom widgets. To load an SVG file, construct a QSvgRenderer with a file name or the contents of a file, or call QSvgRenderer::load() on an existing renderer. If the SVG file has been loaded successfully the QSvgRenderer::isValid() will return true.

Once you have loaded the SVG file successfully, you can render it with the QSvgRenderer::render() function. Note that this scheme allows you to render SVG files on all paint devices supported by Qt, including QWidget, QGLWidget, and QImage. See the SVG Viewer example for more details.

[Previous: The Coordinate System] [The Paint System] [Next: Styling]


Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.6.0