You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/qimageio.html

373 lines
18 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qimage.cpp:3715 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQImageIO Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
<a href="index.html">
<font color="#004faf">Home</font></a>
| <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
| <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
| <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
| <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
| <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>TQImageIO Class Reference</h1>
<p>The TQImageIO class contains parameters for loading and
saving images.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qimage-h.html">qimage.h</a>&gt;</tt>
<p><a href="qimageio-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#TQImageIO"><b>TQImageIO</b></a> ()</li>
<li class=fn><a href="#TQImageIO-2"><b>TQImageIO</b></a> ( TQIODevice&nbsp;*&nbsp;ioDevice, const&nbsp;char&nbsp;*&nbsp;format )</li>
<li class=fn><a href="#TQImageIO-3"><b>TQImageIO</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;fileName, const&nbsp;char&nbsp;*&nbsp;format )</li>
<li class=fn><a href="#~TQImageIO"><b>~TQImageIO</b></a> ()</li>
<li class=fn>const TQImage &amp; <a href="#image"><b>image</b></a> () const</li>
<li class=fn>int <a href="#status"><b>status</b></a> () const</li>
<li class=fn>const char * <a href="#format"><b>format</b></a> () const</li>
<li class=fn>TQIODevice * <a href="#ioDevice"><b>ioDevice</b></a> () const</li>
<li class=fn>TQString <a href="#fileName"><b>fileName</b></a> () const</li>
<li class=fn>int <a href="#quality"><b>quality</b></a> () const</li>
<li class=fn>TQString <a href="#description"><b>description</b></a> () const</li>
<li class=fn>const char * <a href="#parameters"><b>parameters</b></a> () const</li>
<li class=fn>float <a href="#gamma"><b>gamma</b></a> () const</li>
<li class=fn>void <a href="#setImage"><b>setImage</b></a> ( const&nbsp;TQImage&nbsp;&amp;&nbsp;image )</li>
<li class=fn>void <a href="#setStatus"><b>setStatus</b></a> ( int&nbsp;status )</li>
<li class=fn>void <a href="#setFormat"><b>setFormat</b></a> ( const&nbsp;char&nbsp;*&nbsp;format )</li>
<li class=fn>void <a href="#setIODevice"><b>setIODevice</b></a> ( TQIODevice&nbsp;*&nbsp;ioDevice )</li>
<li class=fn>void <a href="#setFileName"><b>setFileName</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;fileName )</li>
<li class=fn>void <a href="#setQuality"><b>setQuality</b></a> ( int&nbsp;q )</li>
<li class=fn>void <a href="#setDescription"><b>setDescription</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;description )</li>
<li class=fn>void <a href="#setParameters"><b>setParameters</b></a> ( const&nbsp;char&nbsp;*&nbsp;parameters )</li>
<li class=fn>void <a href="#setGamma"><b>setGamma</b></a> ( float&nbsp;gamma )</li>
<li class=fn>bool <a href="#read"><b>read</b></a> ()</li>
<li class=fn>bool <a href="#write"><b>write</b></a> ()</li>
</ul>
<h2>Static Public Members</h2>
<ul>
<li class=fn>const char * <a href="#imageFormat"><b>imageFormat</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;fileName )</li>
<li class=fn>const char * <a href="#imageFormat-2"><b>imageFormat</b></a> ( TQIODevice&nbsp;*&nbsp;d )</li>
<li class=fn>TQStrList <a href="#inputFormats"><b>inputFormats</b></a> ()</li>
<li class=fn>TQStrList <a href="#outputFormats"><b>outputFormats</b></a> ()</li>
<li class=fn>void <a href="#defineIOHandler"><b>defineIOHandler</b></a> ( const&nbsp;char&nbsp;*&nbsp;format, const&nbsp;char&nbsp;*&nbsp;header, const&nbsp;char&nbsp;*&nbsp;flags, image_io_handler&nbsp;readImage, image_io_handler&nbsp;writeImage )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
<p> The TQImageIO class contains parameters for loading and
saving images.
<p>
<p> TQImageIO contains a <a href="qiodevice.html">TQIODevice</a> object that is used for image data
I/O. The programmer can install new image file formats in addition
to those that TQt provides.
<p> TQt 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), and PPM (P3 or P6).
<p> You don't normally need to use this class; <a href="qpixmap.html#load">TQPixmap::load</a>(),
<a href="qpixmap.html#save">TQPixmap::save</a>(), and <a href="qimage.html">TQImage</a> contain sufficient functionality.
<p> For image files that contain sequences of images, only the first
is read. See <a href="qmovie.html">TQMovie</a> for loading multiple images.
<p> PBM, PGM, and PPM format <em>output</em> is always in the more condensed
raw format. PPM and PGM files with more than 256 levels of
intensity are scaled down when reading.
<p> <b>Warning:</b> If you are in a country which recognizes software patents
and in which Unisys holds a patent on LZW compression and/or
decompression and you want to use GIF, Unisys may retquire you to
license the technology. Such countries include Canada, Japan, the
USA, France, Germany, Italy and the UK.
<p> GIF support may be removed completely in a future version of TQt.
We recommend using the PNG format.
<p> <p>See also <a href="qimage.html">TQImage</a>, <a href="qpixmap.html">TQPixmap</a>, <a href="qfile.html">TQFile</a>, <a href="qmovie.html">TQMovie</a>, <a href="graphics.html">Graphics Classes</a>, <a href="images.html">Image Processing Classes</a>, and <a href="io.html">Input/Output and Networking</a>.
<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="TQImageIO"></a>TQImageIO::TQImageIO ()
</h3>
Constructs a TQImageIO object with all parameters set to zero.
<h3 class=fn><a name="TQImageIO-2"></a>TQImageIO::TQImageIO ( <a href="qiodevice.html">TQIODevice</a>&nbsp;*&nbsp;ioDevice, const&nbsp;char&nbsp;*&nbsp;format )
</h3>
Constructs a TQImageIO object with the I/O device <em>ioDevice</em> and a
<em>format</em> tag.
<h3 class=fn><a name="TQImageIO-3"></a>TQImageIO::TQImageIO ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;fileName, const&nbsp;char&nbsp;*&nbsp;format )
</h3>
Constructs a TQImageIO object with the file name <em>fileName</em> and a
<em>format</em> tag.
<h3 class=fn><a name="~TQImageIO"></a>TQImageIO::~TQImageIO ()
</h3>
Destroys the object and all related data.
<h3 class=fn>void <a name="defineIOHandler"></a>TQImageIO::defineIOHandler ( const&nbsp;char&nbsp;*&nbsp;format, const&nbsp;char&nbsp;*&nbsp;header, const&nbsp;char&nbsp;*&nbsp;flags, image_io_handler&nbsp;readImage, image_io_handler&nbsp;writeImage )<tt> [static]</tt>
</h3>
Defines an image I/O handler for the image format called <em>format</em>, which is recognized using the <a href="qregexp.html#details">regular expression</a> <em>header</em>, read using <em>readImage</em> and
written using <em>writeImage</em>.
<p> <em>flags</em> 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 <em>flags</em> are "T" and the empty string. The "T"
flag means that the image file is a text file, and TQt should treat
all newline conventions as equivalent. (XPM files and some PPM
files are text files for example.)
<p> <em>format</em> is used to select a handler to write a <a href="qimage.html">TQImage</a>; <em>header</em>
is used to select a handler to read an image file.
<p> If <em>readImage</em> is a null pointer, the TQImageIO will not be able
to read images in <em>format</em>. If <em>writeImage</em> is a null pointer,
the TQImageIO will not be able to write images in <em>format</em>. If
both are null, the TQImageIO object is valid but useless.
<p> Example:
<pre>
void readGIF( TQImageIO *image )
{
// read the image using the image-&gt;<a href="#ioDevice">ioDevice</a>()
}
void writeGIF( TQImageIO *image )
{
// write the image using the image-&gt;<a href="#ioDevice">ioDevice</a>()
}
// add the GIF image handler
TQImageIO::<a href="#defineIOHandler">defineIOHandler</a>( "GIF",
"^GIF[0-9][0-9][a-z]",
0,
readGIF,
writeGIF );
</pre>
<p> Before the regex test, all the 0 bytes in the file header are
converted to 1 bytes. This is done because when TQt was
ASCII-based, <a href="qregexp.html">TQRegExp</a> could not handle 0 bytes in strings.
<p> The regexp is only applied on the first 14 bytes of the file.
<p> Note that TQt assumes that there is only one handler per format; if
two handlers support the same format, TQt will choose one
arbitrarily. It is not possible to have one handler support
reading, and another support writing.
<h3 class=fn><a href="qstring.html">TQString</a> <a name="description"></a>TQImageIO::description () const
</h3>
<p> Returns the image description string.
<p> <p>See also <a href="#setDescription">setDescription</a>().
<h3 class=fn><a href="qstring.html">TQString</a> <a name="fileName"></a>TQImageIO::fileName () const
</h3>
<p> Returns the file name currently set.
<p> <p>See also <a href="#setFileName">setFileName</a>().
<h3 class=fn>const char * <a name="format"></a>TQImageIO::format () const
</h3>
<p> Returns the image format string or 0 if no format has been
explicitly set.
<h3 class=fn>float <a name="gamma"></a>TQImageIO::gamma () const
</h3>
Returns the gamma value at which the image will be viewed.
<p> <p>See also <a href="#setGamma">setGamma</a>().
<h3 class=fn>const&nbsp;<a href="qimage.html">TQImage</a>&nbsp;&amp; <a name="image"></a>TQImageIO::image () const
</h3>
<p> Returns the image currently set.
<p> <p>See also <a href="#setImage">setImage</a>().
<h3 class=fn>const char * <a name="imageFormat"></a>TQImageIO::imageFormat ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;fileName )<tt> [static]</tt>
</h3>
Returns a string that specifies the image format of the file <em>fileName</em>, or null if the file cannot be read or if the format is
not recognized.
<h3 class=fn>const char * <a name="imageFormat-2"></a>TQImageIO::imageFormat ( <a href="qiodevice.html">TQIODevice</a>&nbsp;*&nbsp;d )<tt> [static]</tt>
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> Returns a string that specifies the image format of the image read
from IO device <em>d</em>, or 0 if the device cannot be read or if the
format is not recognized.
<p> Make sure that <em>d</em> is at the right position in the device (for
example, at the beginning of the file).
<p> <p>See also <a href="qiodevice.html#at">TQIODevice::at</a>().
<h3 class=fn><a href="qstrlist.html">TQStrList</a> <a name="inputFormats"></a>TQImageIO::inputFormats ()<tt> [static]</tt>
</h3>
Returns a sorted list of image formats that are supported for
image input.
<h3 class=fn><a href="qiodevice.html">TQIODevice</a>&nbsp;* <a name="ioDevice"></a>TQImageIO::ioDevice () const
</h3>
<p> Returns the IO device currently set.
<p> <p>See also <a href="#setIODevice">setIODevice</a>().
<h3 class=fn><a href="qstrlist.html">TQStrList</a> <a name="outputFormats"></a>TQImageIO::outputFormats ()<tt> [static]</tt>
</h3>
Returns a sorted list of image formats that are supported for
image output.
<p>Example: <a href="scribble-example.html#x911">scribble/scribble.cpp</a>.
<h3 class=fn>const char * <a name="parameters"></a>TQImageIO::parameters () const
</h3>
Returns the image's parameters string.
<p> <p>See also <a href="#setParameters">setParameters</a>().
<h3 class=fn>int <a name="quality"></a>TQImageIO::quality () const
</h3>
Returns the quality of the written image, related to the
compression ratio.
<p> <p>See also <a href="#setQuality">setQuality</a>() and <a href="qimage.html#save">TQImage::save</a>().
<h3 class=fn>bool <a name="read"></a>TQImageIO::read ()
</h3>
Reads an image into memory and returns TRUE if the image was
successfully read; otherwise returns FALSE.
<p> Before reading an image 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.
<p> Setting the image file format string is optional.
<p> Note that this function does <em>not</em> set the <a href="#format">format</a> used to read the image. If you need that
information, use the <a href="#imageFormat">imageFormat</a>() static functions.
<p> Example:
<p> <pre>
TQImageIO iio;
<a href="qpixmap.html">TQPixmap</a> pixmap;
iio.<a href="#setFileName">setFileName</a>( "vegeburger.bmp" );
if ( image.read() ) // ok
pixmap = iio.<a href="#image">image</a>(); // convert to pixmap
</pre>
<p> <p>See also <a href="#setIODevice">setIODevice</a>(), <a href="#setFileName">setFileName</a>(), <a href="#setFormat">setFormat</a>(), <a href="#write">write</a>(), and <a href="qpixmap.html#load">TQPixmap::load</a>().
<h3 class=fn>void <a name="setDescription"></a>TQImageIO::setDescription ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;description )
</h3>
Sets the image description string for image handlers that support
image descriptions to <em>description</em>.
<p> Currently, no image format supported by TQt uses the description
string.
<h3 class=fn>void <a name="setFileName"></a>TQImageIO::setFileName ( const&nbsp;<a href="qstring.html">TQString</a>&nbsp;&amp;&nbsp;fileName )
</h3>
Sets the name of the file to read or write an image from to <em>fileName</em>.
<p> <p>See also <a href="#setIODevice">setIODevice</a>().
<h3 class=fn>void <a name="setFormat"></a>TQImageIO::setFormat ( const&nbsp;char&nbsp;*&nbsp;format )
</h3>
Sets the image format to <em>format</em> for the image to be read or
written.
<p> It is necessary to specify a format before writing an image, but
it is not necessary to specify a format before reading an image.
<p> If no format has been set, TQt guesses the image format before
reading it. If a format is set the image will only be read if it
has that format.
<p> <p>See also <a href="#read">read</a>(), <a href="#write">write</a>(), and <a href="#format">format</a>().
<h3 class=fn>void <a name="setGamma"></a>TQImageIO::setGamma ( float&nbsp;gamma )
</h3>
Sets the gamma value at which the image will be viewed to <em>gamma</em>. If the image format stores a gamma value for which the
image is intended to be used, then this setting will be used to
modify the image. Setting to 0.0 will disable gamma correction
(i.e. any specification in the file will be ignored).
<p> The default value is 0.0.
<p> <p>See also <a href="#gamma">gamma</a>().
<h3 class=fn>void <a name="setIODevice"></a>TQImageIO::setIODevice ( <a href="qiodevice.html">TQIODevice</a>&nbsp;*&nbsp;ioDevice )
</h3>
Sets the IO device to be used for reading or writing an image.
<p> Setting the IO device allows images to be read/written to any
block-oriented <a href="qiodevice.html">TQIODevice</a>.
<p> If <em>ioDevice</em> is not null, this IO device will override file name
settings.
<p> <p>See also <a href="#setFileName">setFileName</a>().
<h3 class=fn>void <a name="setImage"></a>TQImageIO::setImage ( const&nbsp;<a href="qimage.html">TQImage</a>&nbsp;&amp;&nbsp;image )
</h3>
Sets the image to <em>image</em>.
<p> <p>See also <a href="#image">image</a>().
<h3 class=fn>void <a name="setParameters"></a>TQImageIO::setParameters ( const&nbsp;char&nbsp;*&nbsp;parameters )
</h3>
Sets the image's parameter string to <em>parameters</em>. This is for
image handlers that retquire special parameters.
<p> Although the current image formats supported by TQt ignore the
parameters string, it may be used in future extensions or by
contributions (for example, JPEG).
<p> <p>See also <a href="#parameters">parameters</a>().
<h3 class=fn>void <a name="setQuality"></a>TQImageIO::setQuality ( int&nbsp;q )
</h3>
Sets the quality of the written image to <em>q</em>, related to the
compression ratio.
<p> <em>q</em> must be in the range -1..100. Specify 0 to obtain small
compressed files, 100 for large uncompressed files. (-1 signifies
the default compression.)
<p> <p>See also <a href="#quality">quality</a>() and <a href="qimage.html#save">TQImage::save</a>().
<h3 class=fn>void <a name="setStatus"></a>TQImageIO::setStatus ( int&nbsp;status )
</h3>
Sets the image IO status to <em>status</em>. A non-zero value indicates
an error, whereas 0 means that the IO operation was successful.
<p> <p>See also <a href="#status">status</a>().
<h3 class=fn>int <a name="status"></a>TQImageIO::status () const
</h3>
<p> Returns the image's IO status. A non-zero value indicates an
error, whereas 0 means that the IO operation was successful.
<p> <p>See also <a href="#setStatus">setStatus</a>().
<h3 class=fn>bool <a name="write"></a>TQImageIO::write ()
</h3>
Writes an image to an IO device and returns TRUE if the image was
successfully written; otherwise returns FALSE.
<p> Before writing an image 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.
<p> The image will be written using the specified image format.
<p> Example:
<pre>
TQImageIO iio;
<a href="qimage.html">TQImage</a> im;
im = pixmap; // convert to image
iio.<a href="#setImage">setImage</a>( im );
iio.<a href="#setFileName">setFileName</a>( "vegeburger.bmp" );
iio.<a href="#setFormat">setFormat</a>( "BMP" );
if ( iio.<a href="#write">write</a>() )
// returned TRUE if written successfully
</pre>
<p> <p>See also <a href="#setIODevice">setIODevice</a>(), <a href="#setFileName">setFileName</a>(), <a href="#setFormat">setFormat</a>(), <a href="#read">read</a>(), and <a href="qpixmap.html#save">TQPixmap::save</a>().
<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">TQt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>