File: qimagewriter.html

package info (click to toggle)
python-qt4 4.0.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 18,632 kB
  • ctags: 2,639
  • sloc: python: 29,409; sh: 5,646; cpp: 3,168; xml: 149; makefile: 109
file content (131 lines) | stat: -rw-r--r-- 18,166 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QImageWriter Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QImageWriter Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QImageWriter class provides a format independent interface for writing images to files or other devices. <a href="#details">More...</a></p>
<h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qimagewriter.html#ImageWriterError-enum">ImageWriterError</a></b> { UnknownError, DeviceError, UnsupportedFormatError }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qimagewriter.html#QImageWriter">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#QImageWriter-2">__init__</a></b> (<i>self</i>, QIODevice&#160;<i>device</i>, QByteArray&#160;<i>format</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#QImageWriter-3">__init__</a></b> (<i>self</i>, QString&#160;<i>fileName</i>, QByteArray&#160;<i>format</i>&#160;=&#160;QByteArray())</li><li><div class="fn" />bool <b><a href="qimagewriter.html#canWrite">canWrite</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qimagewriter.html#description">description</a></b> (<i>self</i>)</li><li><div class="fn" />QIODevice <b><a href="qimagewriter.html#device">device</a></b> (<i>self</i>)</li><li><div class="fn" />ImageWriterError <b><a href="qimagewriter.html#error">error</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qimagewriter.html#errorString">errorString</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qimagewriter.html#fileName">fileName</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qimagewriter.html#format">format</a></b> (<i>self</i>)</li><li><div class="fn" />float <b><a href="qimagewriter.html#gamma">gamma</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qimagewriter.html#quality">quality</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#setDescription">setDescription</a></b> (<i>self</i>, QString&#160;<i>description</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#setDevice">setDevice</a></b> (<i>self</i>, QIODevice&#160;<i>device</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#setFileName">setFileName</a></b> (<i>self</i>, QString&#160;<i>fileName</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#setFormat">setFormat</a></b> (<i>self</i>, QByteArray&#160;<i>format</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#setGamma">setGamma</a></b> (<i>self</i>, float&#160;<i>gamma</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#setQuality">setQuality</a></b> (<i>self</i>, int&#160;<i>quality</i>)</li><li><div class="fn" /><b><a href="qimagewriter.html#setText">setText</a></b> (<i>self</i>, QString&#160;<i>key</i>, QString&#160;<i>text</i>)</li><li><div class="fn" />bool <b><a href="qimagewriter.html#write">write</a></b> (<i>self</i>, QImage&#160;<i>image</i>)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QByteArray-list <b><a href="qimagewriter.html#supportedImageFormats">supportedImageFormats</a></b> ()</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QImageWriter class provides a format independent interface for writing images to files or other devices.</p>
<p>QImageWriter 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 <a href="qimage.html#save">QImage.save</a>() or <a href="qpixmap.html#save">QPixmap.save</a>() instead.</p>
<p>To store an image, you start by constructing a QImageWriter object. Pass either a file name or a device pointer, and the image format to QImageWriter's constructor. You can then set several options, such as the gamma level (by calling <a href="qimagewriter.html#setGamma">setGamma</a>()) and quality (by calling <a href="qimagewriter.html#setQuality">setQuality</a>()). <a href="qimagewriter.html#canWrite">canWrite</a>() returns true if QImageWriter can write the image (i.e., the image format is supported and the device is open for writing). Call <a href="qimagewriter.html#write">write</a>() to write the image to the device.</p>
<p>If any error occurs when writing the image, <a href="qimagewriter.html#write">write</a>() will return false. You can then call <a href="qimagewriter.html#error">error</a>() to find the type of error that occurred, or <a href="qimagewriter.html#errorString">errorString</a>() to get a human readable description of what went wrong.</p>
<p>Call <a href="qimagewriter.html#supportedImageFormats">supportedImageFormats</a>() for a list of formats that QImageWriter can write. QImageWriter supports all built-in image formats, in addition to any image format plugins that support writing.</p>
<p>See also <a href="qimagereader.html">QImageReader</a>, <a href="qimageiohandler.html">QImageIOHandler</a>, and <a href="qimageioplugin.html">QImageIOPlugin</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="ImageWriterError-enum" />QImageWriter.ImageWriterError</h3><p>This enum describes errors that can occur when writing images with <a href="qimagewriter.html">QImageWriter</a>.</p>
<table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QImageWriter.DeviceError</tt></td>
<td align="center" valign="top"><tt>1</tt></td>
<td valign="top"><a href="qimagewriter.html">QImageWriter</a> encountered a device error when writing the image data. Consult your device for more details on what went wrong.</td>
</tr>
<tr>
<td valign="top"><tt>QImageWriter.UnsupportedFormatError</tt></td>
<td align="center" valign="top"><tt>2</tt></td>
<td valign="top">Qt does not support the requested image format.</td>
</tr>
<tr>
<td valign="top"><tt>QImageWriter.UnknownError</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">An unknown error occurred. If you get this value after calling <a href="qimagewriter.html#write">write</a>(), it is most likely caused by a bug in <a href="qimagewriter.html">QImageWriter</a>.</td>
</tr>
</table>
<br />
<br />
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QImageWriter" />QImageWriter.__init__ (<i>self</i>)</h3><p>Constructs an empty <a href="qimagewriter.html">QImageWriter</a> object. Before writing, you must call <a href="qimagewriter.html#setFormat">setFormat</a>() to set an image format, then <a href="qimagewriter.html#setDevice">setDevice</a>() or <a href="qimagewriter.html#setFileName">setFileName</a>().</p>
<h3 class="fn"><a name="QImageWriter-2" />QImageWriter.__init__ (<i>self</i>, <a href="qiodevice.html">QIODevice</a>&#160;<i>device</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>format</i>)</h3><p>Constructs a <a href="qimagewriter.html">QImageWriter</a> object using the device <i>device</i> and image format <i>format</i>.</p>
<h3 class="fn"><a name="QImageWriter-3" />QImageWriter.__init__ (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>fileName</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>format</i>&#160;=&#160;QByteArray())</h3><p>Constructs a <a href="qimagewriter.html">QImageWriter</a> objects that will write to a file with the name <i>fileName</i>, using the image format <i>format</i>. If <i>format</i> is not provided, <a href="qimagewriter.html">QImageWriter</a> will detect the image format by inspecting the extension of <i>fileName</i>.</p>
<h3 class="fn"><a name="canWrite" />bool QImageWriter.canWrite (<i>self</i>)</h3><p>Returns true if <a href="qimagewriter.html">QImageWriter</a> can write the image (i.e., the image format is supported and the assigned device is open for reading.</p>
<p>See also <a href="qimagewriter.html#write">write</a>(), <a href="qimagewriter.html#setDevice">setDevice</a>(), and <a href="qimagewriter.html#setFormat">setFormat</a>().</p>
<h3 class="fn"><a name="description" /><a href="qstring.html">QString</a> QImageWriter.description (<i>self</i>)</h3><h3 class="fn"><a name="device" /><a href="qiodevice.html">QIODevice</a> QImageWriter.device (<i>self</i>)</h3><p>Returns the device currently assigned to <a href="qimagewriter.html">QImageWriter</a>, or 0 if no device has been assigned.</p>
<p>See also <a href="qimagewriter.html#setDevice">setDevice</a>().</p>
<h3 class="fn"><a name="error" /><a href="qimagewriter.html#ImageWriterError-enum">ImageWriterError</a> QImageWriter.error (<i>self</i>)</h3><p>Returns the type of error that last occurred.</p>
<p>See also <a href="qimagewriter.html#ImageWriterError-enum">ImageWriterError</a> and <a href="qimagewriter.html#errorString">errorString</a>().</p>
<h3 class="fn"><a name="errorString" /><a href="qstring.html">QString</a> QImageWriter.errorString (<i>self</i>)</h3><p>Returns a human readable description of the last error that occurred.</p>
<p>See also <a href="qimagewriter.html#error">error</a>().</p>
<h3 class="fn"><a name="fileName" /><a href="qstring.html">QString</a> QImageWriter.fileName (<i>self</i>)</h3><p>If the currently assigned device is a <a href="qfile.html">QFile</a>, or if <a href="qimagewriter.html#setFileName">setFileName</a>() has been called, this function returns the name of the file <a href="qimagewriter.html">QImageWriter</a> writes to. Otherwise (i.e., if no device has been assigned or the device is not a <a href="qfile.html">QFile</a>), an empty <a href="qstring.html">QString</a> is returned.</p>
<p>See also <a href="qimagewriter.html#setFileName">setFileName</a>() and <a href="qimagewriter.html#setDevice">setDevice</a>().</p>
<h3 class="fn"><a name="format" /><a href="qbytearray.html">QByteArray</a> QImageWriter.format (<i>self</i>)</h3><p>Returns the format <a href="qimagewriter.html">QImageWriter</a> uses for writing images.</p>
<p>See also <a href="qimagewriter.html#setFormat">setFormat</a>().</p>
<h3 class="fn"><a name="gamma" />float QImageWriter.gamma (<i>self</i>)</h3><p>Returns the gamma level of the image.</p>
<p>See also <a href="qimagewriter.html#setGamma">setGamma</a>().</p>
<h3 class="fn"><a name="quality" />int QImageWriter.quality (<i>self</i>)</h3><p>Returns the quality level of the image.</p>
<p>See also <a href="qimagewriter.html#setQuality">setQuality</a>().</p>
<h3 class="fn"><a name="setDescription" />QImageWriter.setDescription (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>description</i>)</h3><h3 class="fn"><a name="setDevice" />QImageWriter.setDevice (<i>self</i>, <a href="qiodevice.html">QIODevice</a>&#160;<i>device</i>)</h3><p>Sets <a href="qimagewriter.html">QImageWriter</a>'s device to <i>device</i>. If a device has already been set, the old device is removed from <a href="qimagewriter.html">QImageWriter</a> and is otherwise left unchanged.</p>
<p>If the device is not already open, <a href="qimagewriter.html">QImageWriter</a> will attempt to open the device in <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.WriteOnly</a> mode by calling open(). Note that this does not work for certain devices, such as <a href="qprocess.html">QProcess</a>, <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qudpsocket.html">QUdpSocket</a>, where more logic is required to open the device.</p>
<p>See also <a href="qimagewriter.html#device">device</a>() and <a href="qimagewriter.html#setFileName">setFileName</a>().</p>
<h3 class="fn"><a name="setFileName" />QImageWriter.setFileName (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>fileName</i>)</h3><p>Sets the file name of <a href="qimagewriter.html">QImageWriter</a> to <i>fileName</i>. Internally, <a href="qimagewriter.html">QImageWriter</a> will create a <a href="qfile.html">QFile</a> and open it in <a href="qiodevice.html#OpenModeFlag-enum">QIODevice.WriteOnly</a> mode, and use this file when writing images.</p>
<p>See also <a href="qimagewriter.html#fileName">fileName</a>() and <a href="qimagewriter.html#setDevice">setDevice</a>().</p>
<h3 class="fn"><a name="setFormat" />QImageWriter.setFormat (<i>self</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>format</i>)</h3><p>Sets the format <a href="qimagewriter.html">QImageWriter</a> will use when writing images, to <i>format</i>. <i>format</i> is a case insensitive text string. Example:</p>
<pre>
    QImageWriter writer;
    writer.setFormat("png"); // same as writer.setFormat("PNG");
</pre>
<p>You can call <a href="qimagewriter.html#supportedImageFormats">supportedImageFormats</a>() for the full list of formats <a href="qimagewriter.html">QImageWriter</a> supports.</p>
<p>See also <a href="qimagewriter.html#format">format</a>().</p>
<h3 class="fn"><a name="setGamma" />QImageWriter.setGamma (<i>self</i>, float&#160;<i>gamma</i>)</h3><p>This is an image format specific function that sets the gamma level of the image to <i>gamma</i>. For image formats that do not support setting the gamma level, this value is ignored.</p>
<p>The value range of <i>gamma</i> depends on the image format. For example, the "png" format supports a gamma range from 0.0 to 1.0.</p>
<p>See also <a href="qimagewriter.html#gamma">gamma</a>() and <a href="qimagewriter.html#quality">quality</a>().</p>
<h3 class="fn"><a name="setQuality" />QImageWriter.setQuality (<i>self</i>, int&#160;<i>quality</i>)</h3><p>This is an image format specific function that sets the quality level of the image to <i>quality</i>. For image formats that do not support setting the quality, this value is ignored.</p>
<p>The value range of <i>quality</i> depends on the image format. For example, the "jpeg" format supports a quality range from 0 (low quality, high compression) to 100 (high quality, low compression).</p>
<p>See also <a href="qimagewriter.html#quality">quality</a>().</p>
<h3 class="fn"><a name="setText" />QImageWriter.setText (<i>self</i>, <a href="qstring.html">QString</a>&#160;<i>key</i>, <a href="qstring.html">QString</a>&#160;<i>text</i>)</h3><p>Sets the image text associated with the key <i>key</i> to <i>text</i>. This is useful for storing copyright information or other information about the image. Example:</p>
<pre>
    QImage image("some/image.jpeg");
    QImageWriter writer("images/outimage.png", "png");
    writer.setText("Author", "John Smith");
    writer.write(image);
</pre>
<p>If you want to store a single block of data (e.g., a comment), you can pass an empty key, or use a generic key like "Description".</p>
<p>The key and text will be embedded into the image data after calling <a href="qimagewriter.html#write">write</a>().</p>
<p>Support for this option is implemented through <a href="qimageiohandler.html#ImageOption-enum">QImageIOHandler.Description</a>.</p>
<p>This function was introduced in Qt 4.1.</p>
<p>See also <a href="qimage.html#setText">QImage.setText</a>() and <a href="qimagereader.html#text">QImageReader.text</a>().</p>
<h3 class="fn"><a name="supportedImageFormats" />QByteArray-list QImageWriter.supportedImageFormats ()</h3><p>Returns the list of image formats supported by <a href="qimagewriter.html">QImageWriter</a>.</p>
<p>By default, Qt can write the following formats:</p>
<table align="center" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#A2C511" valign="top">
<th>Format</th>
<th>Description</th>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td>BMP</td>
<td>Windows Bitmap</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td>JPG</td>
<td>Joint Photographic Experts Group</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td>JPEG</td>
<td>Joint Photographic Experts Group</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td>PNG</td>
<td>Portable Network Graphics</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td>PPM</td>
<td>Portable Pixmap</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td>XBM</td>
<td>X11 Bitmap</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td>XPM</td>
<td>X11 Pixmap</td>
</tr>
</table>
<br />
<br />
<p>See also <a href="qimagewriter.html#setFormat">setFormat</a>(), <a href="qimagereader.html#supportedImageFormats">QImageReader.supportedImageFormats</a>(), and <a href="qimageioplugin.html">QImageIOPlugin</a>.</p>
<h3 class="fn"><a name="write" />bool QImageWriter.write (<i>self</i>, <a href="qimage.html">QImage</a>&#160;<i>image</i>)</h3><p>Writes the image <i>image</i> to the assigned device or file name. Returns true on success; otherwise returns false. If the operation fails, you can call <a href="qimagewriter.html#error">error</a>() to find the type of error that occurred, or <a href="qimagewriter.html#errorString">errorString</a>() to get a human readable description of the error.</p>
<p>See also <a href="qimagewriter.html#canWrite">canWrite</a>(), <a href="qimagewriter.html#error">error</a>(), and <a href="qimagewriter.html#errorString">errorString</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt&#160;4.0.1 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.trolltech.com">Trolltech&#160;AS</a> 2006</td><td align="right" width="25%">Qt&#160;4.1.4</td></tr></table></div></address></body></html>