CopperSpice API  1.7.2
QPictureIO Class Reference

The QPictureIO class contains parameters for loading and saving pictures. More...

Public Methods

 QPictureIO ()
 
 QPictureIO (const QString &fileName, const QString &format)
 
 QPictureIO (QIODevice *ioDevice, const QString &format)
 
 ~QPictureIO ()
 
QString description () const
 
QString fileName () const
 
QString format () const
 
float gamma () const
 
QIODeviceioDevice () const
 
const char * parameters () const
 
const QPicturepicture () const
 
int quality () const
 
bool read ()
 
void setDescription (const QString &description)
 
void setFileName (const QString &fileName)
 
void setFormat (const QString &format)
 
void setGamma (float gamma)
 
void setIODevice (QIODevice *ioDevice)
 
void setParameters (const char *parameters)
 
void setPicture (const QPicture &picture)
 
void setQuality (int q)
 
void setStatus (int status)
 
int status () const
 
bool write ()
 

Static Public Methods

static void defineIOHandler (const QString &format, const QString &header, const char *flags, picture_io_handler readPicture, picture_io_handler writePicture)
 
static QStringList inputFormats ()
 
static QStringList outputFormats ()
 
static QString pictureFormat (const QString &fileName)
 
static QString pictureFormat (QIODevice *ioDevice)
 

Detailed Description

The QPictureIO class contains parameters for loading and saving pictures. QPictureIO contains a QIODevice object used for picture data I/O. New picture file formats can be added as a plugin, in addition to those which CopperSpice provides.

You do not normally need to use this class, use QPicture::load() and QPicture::save().

See also
QPicture, QPixmap, QFile

Constructor & Destructor Documentation

QPictureIO::QPictureIO ( )

Constructs a QPictureIO object with all parameters set to zero.

QPictureIO::QPictureIO ( QIODevice ioDevice,
const QString format 
)

Constructs a QPictureIO object with the I/O device ioDevice and a format tag.

QPictureIO::QPictureIO ( const QString fileName,
const QString format 
)

Constructs a QPictureIO object with the file name fileName and a format tag.

QPictureIO::~QPictureIO ( )

Destroys the object and all related data.

Method Documentation

void QPictureIO::defineIOHandler ( const QString format,
const QString header,
const char *  flags,
picture_io_handler  readPicture,
picture_io_handler  writePicture 
)
static

Defines a picture I/O handler for the picture format called format, which is recognized using the regular expression defined in header, read using readPicture and written using writePicture.

Flags is a string of single-character flags for this format. The only flag defined currently is T (upper case), so the only legal value for flags are "T" and the empty string. The "T" flag means that the picture file is a text file, and CopperSpice should treat all newline conventions as equivalent. (XPM files and some PPM files are text files for example.)

The format is used to select a handler to write a QPicture. The header is used to select a handler to read a picture file.

If readPicture is a null pointer, the QPictureIO will not be able to read pictures in format. If writePicture is a null pointer, the QPictureIO will not be able to write pictures in format. If both are null, the QPictureIO object is valid but useless.

void readSVG(QPictureIO *picture) {
// read the picture using the picture->ioDevice()
}
void writeSVG(QPictureIO *picture) {
// write the picture using the picture->ioDevice()
}
// add the SVG picture handler

Before the regular expression test all the null bytes in the file header are converted to a value of 1. The regular expression is only applied on the first 14 bytes of the file.

If one handlerIO supports writing a format and another supports reading it, CopperSpice supports both reading and writing. If two handlers support the same operation, CopperSpice chooses one arbitrarily.

QString QPictureIO::description ( ) const

Returns the picture description string.

See also
setDescription()
QString QPictureIO::fileName ( ) const

Returns the file name currently set.

See also
setFileName()
QString QPictureIO::format ( ) const

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

See also
setFormat()
float QPictureIO::gamma ( ) const

Returns the gamma value at which the picture will be viewed.

See also
setGamma()
QStringList QPictureIO::inputFormats ( )
static

Returns a sorted list of picture formats that are supported for picture input.

QIODevice * QPictureIO::ioDevice ( ) const

Returns the IO device currently set.

See also
setIODevice()
QStringList QPictureIO::outputFormats ( )
static

Returns a sorted list of picture formats that are supported for picture output.

const char * QPictureIO::parameters ( ) const

Returns the picture's parameters string.

See also
setParameters()
const QPicture & QPictureIO::picture ( ) const

Returns the picture currently set.

See also
setPicture()
QString QPictureIO::pictureFormat ( const QString fileName)
static

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

QString QPictureIO::pictureFormat ( QIODevice ioDevice)
static

Returns a string that specifies the picture format of the picture read from IO device ioDevice or an empty string if the device can not be read or if the format is not recognized.

Make sure that ioDevice is at the right position in the device (for example, at the beginning of the file).

See also
QIODevice::at()
int QPictureIO::quality ( ) const

Returns the quality of the written picture, related to the compression ratio.

See also
setQuality(), QPicture::save()
bool QPictureIO::read ( )

Reads a picture into memory and returns true if the picture was successfully read, otherwise returns false. Before reading a picture you must set an IO device or a file name. If both an IO device and a file name have been set, the IO device will be used.

Setting the picture file format string is optional.

This method does not set the format used to read the picture. If you need this information, use the pictureFormat() static methods.

QPixmap pixmap;
data.setFileName("veggieburger.pic");
if (data.read()) {
QPicture picture = data.picture();
QPainter painter(&pixmap);
painter.drawPicture(0, 0, picture);
}
See also
setIODevice(), setFileName(), setFormat(), write(), QPixmap::load()
void QPictureIO::setDescription ( const QString description)

Sets the picture description string for picture handlers that support picture descriptions to description. Currently, no picture format supported by CopperSpice uses the description string.

See also
description()
void QPictureIO::setFileName ( const QString fileName)

Sets the name of the file to read or write a picture from to fileName.

See also
fileName(), setIODevice()
void QPictureIO::setFormat ( const QString format)

Sets the picture format to format for the picture to be read or written.

It is necessary to specify a format before writing a picture, but it is not necessary to specify a format before reading a picture.

If no format has been set, CopperSpice guesses the picture format before reading it. If a format is set the picture will only be read if it has that format.

See also
read(), write(), format()
void QPictureIO::setGamma ( float  gamma)

Sets the gamma value at which the picture will be viewed to gamma. If the picture format stores a gamma value for which the picture is intended to be used, then this setting will be used to modify the picture. Setting to 0.0 will disable gamma correction (i.e. any specification in the file will be ignored).

The default value is 0.0.

See also
gamma()
void QPictureIO::setIODevice ( QIODevice ioDevice)

Sets the IO device to be used for reading or writing a picture to ioDevice. Setting the IO device allows pictures to be read/written to any block-oriented QIODevice.

If ioDevice is not a nullptr then this IO device will override file name settings.

See also
setFileName()
void QPictureIO::setParameters ( const char *  parameters)

Sets the picture's parameter string to parameters. This is for picture handlers that require special parameters.

Although the current picture formats supported by CopperSpice ignore the parameters string, it may be used in future extensions or by contributions (for example, JPEG).

See also
parameters()
void QPictureIO::setPicture ( const QPicture picture)

Sets the picture to picture.

See also
picture()
void QPictureIO::setQuality ( int  q)

Sets the quality of the written picture to q, related to the compression ratio. The value for q must be in the range -1..100. Specify 0 to obtain small compressed files, 100 for large uncompressed files. (-1 signifies the default compression.)

See also
quality(), QPicture::save()
void QPictureIO::setStatus ( int  status)

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

See also
status()
int QPictureIO::status ( ) const

Returns the picture's IO status. A non-zero value indicates an error, whereas 0 means that the IO operation was successful.

See also
setStatus()
bool QPictureIO::write ( )

Writes a picture to an IO device and returns true if the picture was successfully written, otherwise returns false. Before writing a picture you must set an IO device or a file name. If both an IO device and a file name have been set, the IO device will be used.

The picture will be written using the specified picture format.

QPainter painter(&picture);
painter.drawPixmap(0, 0, pixmap);
data.setPicture(picture);
data.setFileName("veggieburger.pic");
data.setFormat("PIC");
if (data.write()) {
return true; // returns true if written successfully
}
See also
setIODevice(), setFileName(), setFormat(), read(), QPixmap::save()