QPictureIO Class Reference

[ QtGui module]

The QPictureIO class contains parameters for loading and saving pictures. 更多...

方法

Static Methods


详细描述

The QPictureIO class contains parameters for loading and saving pictures.

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

You don't normally need to use this class; QPicture.load (), QPicture.save ().


方法文档编制

QPictureIO.__init__ ( self )

构造 QPictureIO object with all parameters set to zero.

QPictureIO.__init__ ( self , QIODevice   ioDevice , str  format )

构造 QPictureIO object with the I/O device ioDevice format tag.

QPictureIO.__init__ ( self , QString  fileName , str  format )

构造 QPictureIO object with the file name fileName format tag.

QPictureIO.defineIOHandler (str  format , str  header , str  flags , callable  read_picture , callable  write_picture )

read_picture argument may also be None.

write_picture argument may also be None.

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 使用 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 Qt should treat all newline conventions as equivalent. (XPM files and some PPM files are text files for example.)

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

readPicture is a null pointer, the QPictureIO will not be able to read pictures in format 。若 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 0 bytes in the file header are converted to 1 bytes. This is done because when Qt was ASCII-based, QRegExp could not handle 0 bytes in strings.

The regexp is only applied on the first 14 bytes of the 文件。

(Note that if one handlerIO supports writing a format and another supports reading it, Qt supports both reading and writing. If two handlers support the same operation, Qt chooses one arbitrarily.)

QString QPictureIO.description ( self )

Returns the picture description string.

另请参阅 setDescription ().

QString QPictureIO.fileName ( self )

Returns the file name currently set.

另请参阅 setFileName ().

str QPictureIO.format ( self )

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

另请参阅 setFormat ().

float QPictureIO.gamma ( self )

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

另请参阅 setGamma ().

list-of-QByteArray QPictureIO.inputFormats ()

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

QIODevice QPictureIO.ioDevice ( self )

Returns the IO device currently set.

另请参阅 setIODevice ().

list-of-QByteArray QPictureIO.outputFormats ()

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

str QPictureIO.parameters ( self )

Returns the picture's parameters string.

另请参阅 setParameters ().

QPicture QPictureIO.picture ( self )

Returns the picture currently set.

另请参阅 setPicture ().

QByteArray QPictureIO.pictureFormat (QString  fileName )

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

QByteArray QPictureIO.pictureFormat ( QIODevice )

这是重载函数。

Returns a string that specifies the picture format of the picture read from IO device d , or 0 if the device cannot be read or if the format is not recognized.

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

另请参阅 QIODevice.at ().

int QPictureIO.quality ( self )

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

另请参阅 setQuality () 和 QPicture.save ().

bool QPictureIO.read ( self )

Reads an picture into memory and returns true if the picture was successfully read; otherwise returns false.

Before reading an 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.

Note that this function does not set the format used to read the picture. If you need that information, use the pictureFormat () static 函数。

范例:

         QPictureIO iio;
         QPixmap  pixmap;
         iio.setFileName("vegeburger.pic");
         if (iio.read()) {        // OK
             QPicture picture = iio.picture();
             QPainter painter(&pixmap);
             painter.drawPicture(0, 0, picture);
         }
			

另请参阅 setIODevice (), setFileName (), setFormat (), write (),和 QPixmap.load ().

QPictureIO.setDescription ( self , QString)

Sets the picture description string for picture handlers that support picture descriptions to description .

Currently, no picture format supported by Qt uses the description string.

另请参阅 description ().

QPictureIO.setFileName ( self , QString)

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

另请参阅 fileName () 和 setIODevice ().

QPictureIO.setFormat ( self , str)

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

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

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

另请参阅 read (), write (),和 format ().

QPictureIO.setGamma ( self , float)

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.

另请参阅 gamma ().

QPictureIO.setIODevice ( self , QIODevice )

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

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

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

另请参阅 setFileName ().

QPictureIO.setParameters ( self , str)

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

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

另请参阅 参数 ().

QPictureIO.setPicture ( self , QPicture )

Sets the picture to picture .

另请参阅 picture ().

QPictureIO.setQuality ( self , int)

Sets the quality of the written picture to q , related to the compression ratio.

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

另请参阅 quality () and QPicture.save ().

QPictureIO.setStatus ( self , int)

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

另请参阅 status ().

int QPictureIO.status ( self )

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

另请参阅 setStatus ().

bool QPictureIO.write ( self )

Writes an picture to an IO device and returns true if the picture was successfully written; otherwise returns false.

Before writing an 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.

范例:

         QPictureIO iio;
         QPicture   picture;
         QPainter painter(&picture);
         painter.drawPixmap(0, 0, pixmap);
         iio.setPicture(picture);
         iio.setFileName("vegeburger.pic");
         iio.setFormat("PIC");
         if (iio.write())
             return true; // returned true if written successfully
			

另请参阅 setIODevice (), setFileName (), setFormat (), read (),和 QPixmap.save ().