CopperSpice API  1.9.1
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, CopperSpice 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.

CopperSpice also 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 is a convenience class for displaying animations using the QImageReader class.

Once created the QMovie object provides various methods for 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. QImageIOHandler objects are used internally by QImageReader and QImageWriter to add support for different image formats.

A list of the supported file formats are available through the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions. CopperSpice 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.

The CopperSpice 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

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 CopperSpice. SVG 1.2 is the specification currently being developed by the SVG Working Group.

The SVG Basic and SVG Tiny are aimed at resource limited devices and are part of the 3GPP platform for third generation mobile phones. Our libraries support 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. This scheme allows you to render SVG files on all paint devices supported by CopperSpice including QWidget, QGLWidget, and QImage.