File: qimagewriter.html

package info (click to toggle)
python-qt4 4.12.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 40,300 kB
  • ctags: 6,185
  • sloc: python: 125,988; cpp: 13,291; xml: 292; makefile: 246; php: 27; sh: 2
file content (280 lines) | stat: -rw-r--r-- 21,176 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?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="index.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" />int <b><a href="qimagewriter.html#compression">compression</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#setCompression">setCompression</a></b> (<i>self</i>, int&#160;<i>compression</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#supportsOption">supportsOption</a></b> (<i>self</i>, QImageIOHandler.ImageOption&#160;<i>option</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" />unknown-type <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>
<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 class="valuelist">
<tr class="odd" valign="top">
<th class="tblConst">Constant</th>
<th class="tblval">Value</th>
<th class="tbldscr">Description</th>
</tr>
<tr>
<td class="topAlign"><tt>QImageWriter.DeviceError</tt></td>
<td class="topAlign"><tt>1</tt></td>
<td class="topAlign"><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 class="topAlign">
<tt>QImageWriter.UnsupportedFormatError</tt></td>
<td class="topAlign"><tt>2</tt></td>
<td class="topAlign">Qt does not support the requested image
format.</td>
</tr>
<tr>
<td class="topAlign"><tt>QImageWriter.UnknownError</tt></td>
<td class="topAlign"><tt>0</tt></td>
<td class="topAlign">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>
<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>, QString&#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><b>See also</b> <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="compression" />int QImageWriter.compression (<i>self</i>)</h3><p>Returns the compression of the image.</p>
<p><b>See also</b> <a href="qimagewriter.html#setCompression">setCompression</a>().</p>


<h3 class="fn"><a name="description" />QString 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><b>See also</b> <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><b>See also</b> <a href="qimagewriter.html#ImageWriterError-enum">ImageWriterError</a> and
<a href="qimagewriter.html#errorString">errorString</a>().</p>


<h3 class="fn"><a name="errorString" />QString QImageWriter.errorString (<i>self</i>)</h3><p>Returns a human readable description of the last error that
occurred.</p>
<p><b>See also</b> <a href="qimagewriter.html#error">error</a>().</p>


<h3 class="fn"><a name="fileName" />QString 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><b>See also</b> <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><b>See also</b> <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><b>See also</b> <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><b>See also</b> <a href="qimagewriter.html#setQuality">setQuality</a>().</p>


<h3 class="fn"><a name="setCompression" />QImageWriter.setCompression (<i>self</i>, int&#160;<i>compression</i>)</h3><p>This is an image format specific function that set the
compression of an image. For image formats that do not support
setting the compression, this value is ignored.</p>
<p>The value range of <i>compression</i> depends on the image
format. For example, the "tiff" format supports two values, 0(no
compression) and 1(LZW-compression).</p>
<p><b>See also</b> <a href="qimagewriter.html#compression">compression</a>().</p>


<h3 class="fn"><a name="setDescription" />QImageWriter.setDescription (<i>self</i>, QString&#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><b>See also</b> <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>, QString&#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><b>See also</b> <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 class="cpp">
 <span class="type"><a href="qimagewriter.html">QImageWriter</a></span> writer;
 writer<span class="operator">.</span>setFormat(<span class="string">"png"</span>); <span class="comment">// same as writer.setFormat("PNG");</span>
</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><b>See also</b> <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><b>See also</b> <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><b>See also</b> <a href="qimagewriter.html#quality">quality</a>().</p>


<h3 class="fn"><a name="setText" />QImageWriter.setText (<i>self</i>, QString&#160;<i>key</i>, QString&#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 class="cpp">
 <span class="type"><a href="qimage.html">QImage</a></span> image(<span class="string">"some/image.jpeg"</span>);
 <span class="type"><a href="qimagewriter.html">QImageWriter</a></span> writer(<span class="string">"images/outimage.png"</span><span class="operator">,</span> <span class="string">"png"</span>);
 writer<span class="operator">.</span>setText(<span class="string">"Author"</span><span class="operator">,</span> <span class="string">"John Smith"</span>);
 writer<span class="operator">.</span><a href="qimagewriter.html#write">write</a>(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><b>See also</b> <a href="qimage.html#setText">QImage.setText</a>() and <a href="qimagereader.html#text">QImageReader.text</a>().</p>


<h3 class="fn"><a name="supportedImageFormats" />unknown-type 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 class="generic">
<thead>
<tr class="qt-style">
<th>Format</th>
<th>Description</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td>BMP</td>
<td>Windows Bitmap</td>
</tr>
<tr class="even" valign="top">
<td>JPG</td>
<td>Joint Photographic Experts Group</td>
</tr>
<tr class="odd" valign="top">
<td>JPEG</td>
<td>Joint Photographic Experts Group</td>
</tr>
<tr class="even" valign="top">
<td>PNG</td>
<td>Portable Network Graphics</td>
</tr>
<tr class="odd" valign="top">
<td>PPM</td>
<td>Portable Pixmap</td>
</tr>
<tr class="even" valign="top">
<td>TIFF</td>
<td>Tagged Image File Format</td>
</tr>
<tr class="odd" valign="top">
<td>XBM</td>
<td>X11 Bitmap</td>
</tr>
<tr class="even" valign="top">
<td>XPM</td>
<td>X11 Pixmap</td>
</tr>
</table>
<p>Reading and writing SVG files is supported through Qt's <a href="qtsvg.html">SVG Module</a>.</p>
<p>Note that the <a href="qapplication.html">QApplication</a>
instance must be created before this function is called.</p>
<p><b>See also</b> <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="supportsOption" />bool QImageWriter.supportsOption (<i>self</i>, <a href="qimageiohandler.html#ImageOption-enum">QImageIOHandler.ImageOption</a>&#160;<i>option</i>)</h3><p>Returns true if the writer supports <i>option</i>; otherwise
returns false.</p>
<p>Different image formats support different options. Call this
function to determine whether a certain option is supported by the
current format. For example, the PNG format allows you to embed
text into the image's metadata (see text()).</p>
<pre class="cpp">
 <span class="type"><a href="qimagewriter.html">QImageWriter</a></span> writer(fileName);
 <span class="keyword">if</span> (writer<span class="operator">.</span>supportsOption(<span class="type"><a href="qimageiohandler.html">QImageIOHandler</a></span><span class="operator">.</span>Description))
     writer<span class="operator">.</span><a href="qimagewriter.html#setText">setText</a>(<span class="string">"Author"</span><span class="operator">,</span> <span class="string">"John Smith"</span>);
</pre>
<p>Options can be tested after the writer has been associated with
a format.</p>
<p>This function was introduced in Qt 4.2.</p>
<p><b>See also</b> <a href="qimagereader.html#supportsOption">QImageReader.supportsOption</a>()
and <a href="qimagewriter.html#setFormat">setFormat</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><b>See also</b> <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 align="left" width="25%">PyQt&#160;4.12.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.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt&#160;4.8.7</td></tr></table></div></address></body></html>