File: image.html

package info (click to toggle)
pygame 2.1.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,416 kB
  • sloc: ansic: 66,042; python: 46,176; javascript: 9,214; objc: 273; sh: 78; makefile: 56; cpp: 25
file content (459 lines) | stat: -rw-r--r-- 29,060 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459

<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>pygame.image &#8212; pygame v2.1.2 documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/pygame.css" />
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../_static/pygame.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="pygame.joystick" href="joystick.html" />
    <link rel="prev" title="pygame.gfxdraw" href="gfxdraw.html" /> 
  </head><body>  

    <div class="document">

  <div class="header">
    <table>
      <tr>
	<td class="logo">
	  <a href="https://www.pygame.org/">
	    <img src="../_static/pygame_tiny.png"/>
	  </a>
	  <h5>pygame documentation</h5>
	</td>
	<td class="pagelinks">
	  <div class="top">
	    <a href="https://www.pygame.org/">Pygame Home</a> ||
	    <a href="../index.html">Help Contents</a> ||
	    <a href="../genindex.html">Reference Index</a>

        <form action="../search.html" method="get" style="display:inline;float:right;">
          <input name="q" value="" type="text">
          <input value="search" type="submit">
        </form>
	  </div>
	  <hr style="color:black;border-bottom:none;border-style: dotted;border-bottom-style:none;">
	  <p class="bottom"><b>Most useful stuff</b>:
	    <a href="color.html">Color</a> | 
	    <a href="display.html">display</a> | 
	    <a href="draw.html">draw</a> | 
	    <a href="event.html">event</a> | 
	    <a href="font.html">font</a> | 
	    <a href="image.html">image</a> | 
	    <a href="key.html">key</a> | 
	    <a href="locals.html">locals</a> | 
	    <a href="mixer.html">mixer</a> | 
	    <a href="mouse.html">mouse</a> | 
	    <a href="rect.html">Rect</a> | 
	    <a href="surface.html">Surface</a> | 
	    <a href="time.html">time</a> | 
	    <a href="music.html">music</a> | 
	    <a href="pygame.html">pygame</a>
	  </p>

	  <p class="bottom"><b>Advanced stuff</b>:
	    <a href="cursors.html">cursors</a> | 
	    <a href="joystick.html">joystick</a> | 
	    <a href="mask.html">mask</a> | 
	    <a href="sprite.html">sprite</a> | 
	    <a href="transform.html">transform</a> | 
	    <a href="bufferproxy.html">BufferProxy</a> | 
	    <a href="freetype.html">freetype</a> | 
	    <a href="gfxdraw.html">gfxdraw</a> | 
	    <a href="midi.html">midi</a> | 
	    <a href="pixelarray.html">PixelArray</a> | 
	    <a href="pixelcopy.html">pixelcopy</a> | 
	    <a href="sndarray.html">sndarray</a> | 
	    <a href="surfarray.html">surfarray</a> | 
	    <a href="math.html">math</a>
	  </p>

	  <p class="bottom"><b>Other</b>:
	    <a href="camera.html">camera</a> | 
	    <a href="sdl2_controller.html#module-pygame._sdl2.controller">controller</a> | 
	    <a href="examples.html">examples</a> | 
	    <a href="fastevent.html">fastevent</a> | 
	    <a href="scrap.html">scrap</a> | 
	    <a href="tests.html">tests</a> | 
	    <a href="touch.html">touch</a> | 
	    <a href="pygame.html#module-pygame.version">version</a>
	  </p>
	</td>
      </tr>
    </table>
  </div>

      <div class="documentwrapper">
          <div class="body" role="main">
            
<section id="module-pygame.image">
<span id="pygame-image"></span><dl class="definition">
<dt class="title module sig sig-object">
<code class="docutils literal notranslate"><span class="pre">pygame.image</span></code></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">pygame module for image transfer</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 34%" />
<col style="width: 1%" />
<col style="width: 65%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.load">pygame.image.load</a></div>
</td>
<td>—</td>
<td>load new image from a file (or file-like object)</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.save">pygame.image.save</a></div>
</td>
<td>—</td>
<td>save an image to file (or file-like object)</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.get_sdl_image_version">pygame.image.get_sdl_image_version</a></div>
</td>
<td>—</td>
<td>get version number of the SDL_Image library being used</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.get_extended">pygame.image.get_extended</a></div>
</td>
<td>—</td>
<td>test if extended image formats can be loaded</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.tostring">pygame.image.tostring</a></div>
</td>
<td>—</td>
<td>transfer image to string buffer</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.fromstring">pygame.image.fromstring</a></div>
</td>
<td>—</td>
<td>create new Surface from a string buffer</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.frombuffer">pygame.image.frombuffer</a></div>
</td>
<td>—</td>
<td>create a new Surface that shares data inside a bytes buffer</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.load_basic">pygame.image.load_basic</a></div>
</td>
<td>—</td>
<td>load new BMP image from a file (or file-like object)</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.load_extended">pygame.image.load_extended</a></div>
</td>
<td>—</td>
<td>load an image from a file (or file-like object)</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="image.html#pygame.image.save_extended">pygame.image.save_extended</a></div>
</td>
<td>—</td>
<td>save a png/jpg image to file (or file-like object)</td>
</tr>
</tbody>
</table>
<p>The image module contains functions for loading and saving pictures, as well as
transferring Surfaces to formats usable by other packages.</p>
<p>Note that there is no Image class; an image is loaded as a Surface object. The
Surface class allows manipulation (drawing lines, setting pixels, capturing
regions, etc.).</p>
<p>The image module is a required dependency of pygame, but it only optionally
supports any extended file formats. By default it can only load uncompressed
<code class="docutils literal notranslate"><span class="pre">BMP</span></code> images. When built with full image support, the <code class="docutils literal notranslate"><span class="pre">pygame.image.load()</span></code>
function can support the following formats.</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">BMP</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">GIF</span></code> (non-animated)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">JPEG</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">LBM</span></code> (and <code class="docutils literal notranslate"><span class="pre">PBM</span></code>, <code class="docutils literal notranslate"><span class="pre">PGM</span></code>, <code class="docutils literal notranslate"><span class="pre">PPM</span></code>)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PCX</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PNG</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PNM</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">SVG</span></code> (limited support, using Nano SVG)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">TGA</span></code> (uncompressed)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">TIFF</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">WEBP</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">XPM</span></code></p></li>
</ul>
</div></blockquote>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0: </span>Loading SVG, WebP, PNM</p>
</div>
<p>Saving images only supports a limited set of formats. You can save to the
following formats.</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">BMP</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">JPEG</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PNG</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">TGA</span></code></p></li>
</ul>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">JPEG</span></code> and <code class="docutils literal notranslate"><span class="pre">JPG</span></code>, as well as <code class="docutils literal notranslate"><span class="pre">TIF</span></code> and <code class="docutils literal notranslate"><span class="pre">TIFF</span></code> refer to the same file format</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8: </span>Saving PNG and JPEG files.</p>
</div>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.load">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">load</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.load" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">load new image from a file (or file-like object)</span></div>
<div class="line"><span class="signature">load(filename) -&gt; Surface</span></div>
<div class="line"><span class="signature">load(fileobj, namehint=&quot;&quot;) -&gt; Surface</span></div>
</div>
<p>Load an image from a file source. You can pass either a filename, a Python
file-like object, or a pathlib.Path.</p>
<p>Pygame will automatically determine the image type (e.g., <code class="docutils literal notranslate"><span class="pre">GIF</span></code> or bitmap)
and create a new Surface object from the data. In some cases it will need to
know the file extension (e.g., <code class="docutils literal notranslate"><span class="pre">GIF</span></code> images should end in &quot;.gif&quot;). If you
pass a raw file-like object, you may also want to pass the original filename
as the namehint argument.</p>
<p>The returned Surface will contain the same color format, colorkey and alpha
transparency as the file it came from. You will often want to call
<code class="docutils literal notranslate"><span class="pre">Surface.convert()</span></code> with no arguments, to create a copy that will draw
more quickly on the screen.</p>
<p>For alpha transparency, like in .png images, use the <code class="docutils literal notranslate"><span class="pre">convert_alpha()</span></code>
method after loading so that the image has per pixel transparency.</p>
<p>pygame may not always be built to support all image formats. At minimum it
will support uncompressed <code class="docutils literal notranslate"><span class="pre">BMP</span></code>. If <code class="docutils literal notranslate"><span class="pre">pygame.image.get_extended()</span></code>
returns 'True', you should be able to load most images (including PNG, JPG
and GIF).</p>
<p>You should use <code class="docutils literal notranslate"><span class="pre">os.path.join()</span></code> for compatibility.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">eg</span><span class="o">.</span> <span class="n">asurf</span> <span class="o">=</span> <span class="n">pygame</span><span class="o">.</span><span class="n">image</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="s1">&#39;bla.png&#39;</span><span class="p">))</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.save">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">save</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.save" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">save an image to file (or file-like object)</span></div>
<div class="line"><span class="signature">save(Surface, filename) -&gt; None</span></div>
<div class="line"><span class="signature">save(Surface, fileobj, namehint=&quot;&quot;) -&gt; None</span></div>
</div>
<p>This will save your Surface as either a <code class="docutils literal notranslate"><span class="pre">BMP</span></code>, <code class="docutils literal notranslate"><span class="pre">TGA</span></code>, <code class="docutils literal notranslate"><span class="pre">PNG</span></code>, or
<code class="docutils literal notranslate"><span class="pre">JPEG</span></code> image. If the filename extension is unrecognized it will default to
<code class="docutils literal notranslate"><span class="pre">TGA</span></code>. Both <code class="docutils literal notranslate"><span class="pre">TGA</span></code>, and <code class="docutils literal notranslate"><span class="pre">BMP</span></code> file formats create uncompressed files.
You can pass a filename, a pathlib.Path or a Python file-like object.
For file-like object, the image is saved to <code class="docutils literal notranslate"><span class="pre">TGA</span></code> format unless
a namehint with a recognizable extension is passed in.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>When saving to a file-like object, it seems that for most formats,
the object needs to be flushed after saving to it to make loading
from it possible.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 1.8: </span>Saving PNG and JPEG files.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.0: </span>The <code class="docutils literal notranslate"><span class="pre">namehint</span></code> parameter was added to make it possible
to save other formats than <code class="docutils literal notranslate"><span class="pre">TGA</span></code> to a file-like object.
Saving to a file-like object with JPEG is possible.</p>
</div>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.get_sdl_image_version">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">get_sdl_image_version</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.get_sdl_image_version" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get version number of the SDL_Image library being used</span></div>
<div class="line"><span class="signature">get_sdl_image_version() -&gt; None</span></div>
<div class="line"><span class="signature">get_sdl_image_version() -&gt; (major, minor, patch)</span></div>
</div>
<p>If pygame is built with extended image formats, then this function will
return the SDL_Image library's version number as a tuple of 3 integers
<code class="docutils literal notranslate"><span class="pre">(major,</span> <span class="pre">minor,</span> <span class="pre">patch)</span></code>. If not, then it will return <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.0.</span></p>
</div>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.get_extended">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">get_extended</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.get_extended" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">test if extended image formats can be loaded</span></div>
<div class="line"><span class="signature">get_extended() -&gt; bool</span></div>
</div>
<p>If pygame is built with extended image formats this function will return
True. It is still not possible to determine which formats will be available,
but generally you will be able to load them all.</p>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.tostring">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">tostring</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.tostring" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">transfer image to string buffer</span></div>
<div class="line"><span class="signature">tostring(Surface, format, flipped=False) -&gt; string</span></div>
</div>
<p>Creates a string that can be transferred with the 'fromstring' method in
other Python imaging packages. Some Python image packages prefer their
images in bottom-to-top format (PyOpenGL for example). If you pass True for
the flipped argument, the string buffer will be vertically flipped.</p>
<p>The format argument is a string of one of the following values. Note that
only 8-bit Surfaces can use the &quot;P&quot; format. The other formats will work for
any Surface. Also note that other Python image packages support more formats
than pygame.</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">P</span></code>, 8-bit palettized Surfaces</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">RGB</span></code>, 24-bit image</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">RGBX</span></code>, 32-bit image with unused space</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">RGBA</span></code>, 32-bit image with an alpha channel</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ARGB</span></code>, 32-bit image with alpha channel first</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">RGBA_PREMULT</span></code>, 32-bit image with colors scaled by alpha channel</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ARGB_PREMULT</span></code>, 32-bit image with colors scaled by alpha channel, alpha channel first</p></li>
</ul>
</div></blockquote>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.fromstring">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">fromstring</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.fromstring" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">create new Surface from a string buffer</span></div>
<div class="line"><span class="signature">fromstring(string, size, format, flipped=False) -&gt; Surface</span></div>
</div>
<p>This function takes arguments similar to <code class="docutils literal notranslate"><span class="pre">pygame.image.tostring()</span></code>. The
size argument is a pair of numbers representing the width and height. Once
the new Surface is created you can destroy the string buffer.</p>
<p>The size and format image must compute the exact same size as the passed
string buffer. Otherwise an exception will be raised.</p>
<p>See the <code class="docutils literal notranslate"><span class="pre">pygame.image.frombuffer()</span></code> method for a potentially faster way to
transfer images into pygame.</p>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.frombuffer">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">frombuffer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.frombuffer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">create a new Surface that shares data inside a bytes buffer</span></div>
<div class="line"><span class="signature">frombuffer(bytes, size, format) -&gt; Surface</span></div>
</div>
<p>Create a new Surface that shares pixel data directly from a bytes buffer.
This method takes similar arguments to <code class="docutils literal notranslate"><span class="pre">pygame.image.fromstring()</span></code>, but
is unable to vertically flip the source data.</p>
<p>This will run much faster than <a class="tooltip reference internal" href="#pygame.image.fromstring" title=""><code class="xref py py-func docutils literal notranslate"><span class="pre">pygame.image.fromstring()</span></code><span class="tooltip-content">create new Surface from a string buffer</span></a>, since no
pixel data must be allocated and copied.</p>
<p>It accepts the following 'format' arguments:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">P</span></code>, 8-bit palettized Surfaces</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">RGB</span></code>, 24-bit image</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">BGR</span></code>, 24-bit image, red and blue channels swapped.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">RGBX</span></code>, 32-bit image with unused space</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">RGBA</span></code>, 32-bit image with an alpha channel</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ARGB</span></code>, 32-bit image with alpha channel first</p></li>
</ul>
</div></blockquote>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.load_basic">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">load_basic</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.load_basic" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">load new BMP image from a file (or file-like object)</span></div>
<div class="line"><span class="signature">load_basic(file) -&gt; Surface</span></div>
</div>
<p>Load an image from a file source. You can pass either a filename or a Python
file-like object, or a pathlib.Path.</p>
<p>This function only supports loading &quot;basic&quot; image format, ie <code class="docutils literal notranslate"><span class="pre">BMP</span></code>
format.
This function is always available, no matter how pygame was built.</p>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.load_extended">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">load_extended</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.load_extended" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">load an image from a file (or file-like object)</span></div>
<div class="line"><span class="signature">load_extended(filename) -&gt; Surface</span></div>
<div class="line"><span class="signature">load_extended(fileobj, namehint=&quot;&quot;) -&gt; Surface</span></div>
</div>
<p>This function is similar to <code class="docutils literal notranslate"><span class="pre">pygame.image.load()</span></code>, except that this
function can only be used if pygame was built with extended image format
support.</p>
<p>From version 2.0.1, this function is always available, but raises an
error if extended image formats are not supported. Previously, this
function may or may not be available, depending on the state of
extended image format support.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.1.</span></p>
</div>
</dd></dl>

<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.image.save_extended">
<span class="sig-prename descclassname"><span class="pre">pygame.image.</span></span><span class="sig-name descname"><span class="pre">save_extended</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.image.save_extended" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">save a png/jpg image to file (or file-like object)</span></div>
<div class="line"><span class="signature">save_extended(Surface, filename) -&gt; None</span></div>
<div class="line"><span class="signature">save_extended(Surface, fileobj, namehint=&quot;&quot;) -&gt; None</span></div>
</div>
<p>This will save your Surface as either a <code class="docutils literal notranslate"><span class="pre">PNG</span></code> or <code class="docutils literal notranslate"><span class="pre">JPEG</span></code> image.</p>
<p>Incase the image is being saved to a file-like object, this function
uses the namehint argument to determine the format of the file being
saved. Saves to <code class="docutils literal notranslate"><span class="pre">JPEG</span></code> incase the namehint was not specified while
saving to file-like object.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.1: </span>This function is always available, but raises an
error if extended image formats are not supported.
Previously, this function may or may not be
available, depending on the state of extended image
format support.</p>
</div>
</dd></dl>

</dd></dl>

</section>


<br /><br />
<hr />
<a href="https://github.com/pygame/pygame/edit/main/docs/reST/ref/image.rst" rel="nofollow">Edit on GitHub</a>
            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="joystick.html" title="pygame.joystick"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="gfxdraw.html" title="pygame.gfxdraw"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">pygame v2.1.2 documentation</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.image</span></code></a></li>
    <script type="text/javascript" src="https://www.pygame.org/comment/jquery.plugin.docscomments.js"></script>

      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2000-2021, pygame developers.
    </div>
  </body>
</html>