pygame / docs / ref / surfarray.html

<html>
<title>surfarray - Pygame Documentation</title>
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>


<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
<tr>
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td>
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
	||&nbsp;
	<a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
	<a href=../index.html>Help Contents</a> &nbsp;||
	<a href=index.html>Reference Index</a> &nbsp;||
	<br>&nbsp;<br>
	
<a href="camera.html">Camera</a>&nbsp;||&nbsp;
<a href="cdrom.html">Cdrom</a>&nbsp;||&nbsp;
<a href="color.html">Color</a>&nbsp;||&nbsp;
<a href="cursors.html">Cursors</a>&nbsp;||&nbsp;
<a href="display.html">Display</a>&nbsp;||&nbsp;
<a href="draw.html">Draw</a>&nbsp;||&nbsp;
<a href="event.html">Event</a>&nbsp;||&nbsp;
<a href="examples.html">Examples</a>&nbsp;||&nbsp;
<a href="font.html">Font</a>&nbsp;||&nbsp;
<a href="gfxdraw.html">Gfxdraw</a>&nbsp;||&nbsp;
<a href="image.html">Image</a>&nbsp;||&nbsp;
<a href="joystick.html">Joystick</a>&nbsp;||&nbsp;
<a href="key.html">Key</a>&nbsp;||&nbsp;
<a href="locals.html">Locals</a>&nbsp;||&nbsp;
<a href="mask.html">Mask</a>&nbsp;||&nbsp;
<a href="midi.html">Midi</a>&nbsp;||&nbsp;
<a href="mixer.html">Mixer</a>&nbsp;||&nbsp;
<a href="mouse.html">Mouse</a>&nbsp;||&nbsp;
<a href="movie.html">Movie</a>&nbsp;||&nbsp;
<a href="music.html">Music</a>&nbsp;||&nbsp;
<a href="overlay.html">Overlay</a>&nbsp;||&nbsp;
<a href="pixelarray.html">Pixelarray</a>&nbsp;||&nbsp;
<a href="pygame.html">Pygame</a>&nbsp;||&nbsp;
<a href="rect.html">Rect</a>&nbsp;||&nbsp;
<a href="scrap.html">Scrap</a>&nbsp;||&nbsp;
<a href="sndarray.html">Sndarray</a>&nbsp;||&nbsp;
<a href="sprite.html">Sprite</a>&nbsp;||&nbsp;
<a href="surface.html">Surface</a>&nbsp;||&nbsp;
<a href="surfarray.html">Surfarray</a>&nbsp;||&nbsp;
<a href="tests.html">Tests</a>&nbsp;||&nbsp;
<a href="time.html">Time</a>&nbsp;||&nbsp;
<a href="transform.html">Transform</a>
</td></tr></table>
<br>


<a name="pygame.surfarray">
<big><b>pygame.surfarray</big></b><br><ul>
  <i>pygame module for accessing surface pixel data using array interfaces</i><br>
<ul><small><table>
  <tr><td><a href="surfarray.html#pygame.surfarray.array2d">pygame.surfarray.array2d</a> - <font size=-1>Copy pixels into a 2d array</font></td><td>Copy pixels into a 2d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.pixels2d">pygame.surfarray.pixels2d</a> - <font size=-1>Reference pixels into a 2d array</font></td><td>Reference pixels into a 2d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.array3d">pygame.surfarray.array3d</a> - <font size=-1>Copy pixels into a 3d array</font></td><td>Copy pixels into a 3d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.pixels3d">pygame.surfarray.pixels3d</a> - <font size=-1>Reference pixels into a 3d array</font></td><td>Reference pixels into a 3d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.array_alpha">pygame.surfarray.array_alpha</a> - <font size=-1>Copy pixel alphas into a 2d array</font></td><td>Copy pixel alphas into a 2d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.pixels_alpha">pygame.surfarray.pixels_alpha</a> - <font size=-1>Reference pixel alphas into a 2d array</font></td><td>Reference pixel alphas into a 2d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.array_colorkey">pygame.surfarray.array_colorkey</a> - <font size=-1>Copy the colorkey values into a 2d array</font></td><td>Copy the colorkey values into a 2d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.make_surface">pygame.surfarray.make_surface</a> - <font size=-1>Copy an array to a new surface</font></td><td>Copy an array to a new surface</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.blit_array">pygame.surfarray.blit_array</a> - <font size=-1>Blit directly from a array values</font></td><td>Blit directly from a array values</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.map_array">pygame.surfarray.map_array</a> - <font size=-1>Map a 3d array into a 2d array</font></td><td>Map a 3d array into a 2d array</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.use_arraytype">pygame.surfarray.use_arraytype</a> - <font size=-1>Sets the array system to be used for surface arrays</font></td><td>Sets the array system to be used for surface arrays</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.get_arraytype">pygame.surfarray.get_arraytype</a> - <font size=-1>Gets the currently active array type.</font></td><td>Gets the currently active array type.</td></tr>
  <tr><td><a href="surfarray.html#pygame.surfarray.get_arraytypes">pygame.surfarray.get_arraytypes</a> - <font size=-1>Gets the array system types currently supported.</font></td><td>Gets the array system types currently supported.</td></tr>
</table></small></ul>
<p>Functions to convert pixel data between pygame Surfaces and arrays. This module will only be functional when pygame can use the external Numpy or Numeric packages. </p>
<p>Every pixel is stored as a single integer value to represent the red, green, and blue colors. The 8bit images use a value that looks into a colormap. Pixels with higher depth use a bit packing process to place three or four values into a single number. </p>
<p>The arrays are indexed by the <tt>X</tt> axis first, followed by the <tt>Y</tt> axis. Arrays that treat the pixels as a single integer are referred to as <tt>2D</tt> arrays. This module can also separate the red, green, and blue color values into separate indices. These types of arrays are referred to as <tt>3D</tt> arrays, and the last index is 0 for red, 1 for green, and 2 for blue. </p>
<p>Supported array systems are </p>
<pre>  numpy
  numeric
</pre><p>The default will be numpy, if installed. Otherwise, Numeric will be set as default if installed. If neither numpy nor Numeric are installed, the module will raise an ImportError. </p>
<p>The array type to use can be changed at runtime using the use_arraytype () method, which requires one of the above types as string. </p>
<p>Note: numpy and Numeric are not completely compatible. Certain array manipulations, which work for one type, might behave differently or even completely break for the other. </p>
<p>Additionally, in contrast to Numeric numpy does use unsigned 16-bit integers. Images with 16-bit data will be treated as unsigned integers. Numeric instead uses signed integers for the representation, which is important to keep in mind, if you use the module's functions and wonder about the values. </p>
<p>The support of numpy is new in pygame <tt>1.8</tt>. </p>
<!--COMMENTS:pygame.surfarray--> &nbsp;<br> 


<a name="pygame.surfarray.array2d">
<big><b>pygame.surfarray.array2d</big></b><br><ul>
  <i>Copy pixels into a 2d array</i><br>
  <tt>pygame.surfarray.array2d(Surface): return array</tt><br>
<p>Copy the pixels from a Surface into a <tt>2D</tt> array. The bit depth of the surface will control the size of the integer values, and will work for any type of pixel format. </p>
<p>This function will temporarily lock the Surface as pixels are copied (see the <tt>Surface.lock</tt> - lock the Surface memory for pixel access method). </p>
<!--COMMENTS:pygame.surfarray.array2d--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.pixels2d">
<big><b>pygame.surfarray.pixels2d</big></b><br><ul>
  <i>Reference pixels into a 2d array</i><br>
  <tt>pygame.surfarray.pixels2d(Surface): return array</tt><br>
<p>Create a new <tt>2D</tt> array that directly references the pixel values in a Surface. Any changes to the array will affect the pixels in the Surface. This is a fast operation since no data is copied. </p>
<p>Pixels from a 24-bit Surface cannot be referenced, but all other Surface bit depths can. </p>
<p>The Surface this references will remain locked for the lifetime of the array (see the <tt>Surface.lock</tt> - lock the Surface memory for pixel access method). </p>
<!--COMMENTS:pygame.surfarray.pixels2d--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.array3d">
<big><b>pygame.surfarray.array3d</big></b><br><ul>
  <i>Copy pixels into a 3d array</i><br>
  <tt>pygame.surfarray.array3d(Surface): return array</tt><br>
<p>Copy the pixels from a Surface into a <tt>3D</tt> array. The bit depth of the surface will control the size of the integer values, and will work for any type of pixel format. </p>
<p>This function will temporarily lock the Surface as pixels are copied (see the <tt>Surface.lock</tt> - lock the Surface memory for pixel access method). </p>
<!--COMMENTS:pygame.surfarray.array3d--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.pixels3d">
<big><b>pygame.surfarray.pixels3d</big></b><br><ul>
  <i>Reference pixels into a 3d array</i><br>
  <tt>pygame.surfarray.pixels3d(Surface): return array</tt><br>
<p>Create a new <tt>3D</tt> array that directly references the pixel values in a Surface. Any changes to the array will affect the pixels in the Surface. This is a fast operation since no data is copied. </p>
<p>This will only work on Surfaces that have 24-bit or 32-bit formats. Lower pixel formats cannot be referenced. </p>
<p>The Surface this references will remain locked for the lifetime of the array (see the <tt>Surface.lock</tt> - lock the Surface memory for pixel access method). </p>
<!--COMMENTS:pygame.surfarray.pixels3d--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.array_alpha">
<big><b>pygame.surfarray.array_alpha</big></b><br><ul>
  <i>Copy pixel alphas into a 2d array</i><br>
  <tt>pygame.surfarray.array_alpha(Surface): return array</tt><br>
<p>Copy the pixel alpha values (degree of transparency) from a Surface into a <tt>2D</tt> array. This will work for any type of Surface format. Surfaces without a pixel alpha will return an array with all opaque values. </p>
<p>This function will temporarily lock the Surface as pixels are copied (see the <tt>Surface.lock</tt> - lock the Surface memory for pixel access method). </p>
<!--COMMENTS:pygame.surfarray.array_alpha--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.pixels_alpha">
<big><b>pygame.surfarray.pixels_alpha</big></b><br><ul>
  <i>Reference pixel alphas into a 2d array</i><br>
  <tt>pygame.surfarray.pixels_alpha(Surface): return array</tt><br>
<p>Create a new <tt>2D</tt> array that directly references the alpha values (degree of transparency) in a Surface. Any changes to the array will affect the pixels in the Surface. This is a fast operation since no data is copied. </p>
<p>This can only work on 32-bit Surfaces with a per-pixel alpha value. </p>
<p>The Surface this array references will remain locked for the lifetime of the array. </p>
<!--COMMENTS:pygame.surfarray.pixels_alpha--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.array_colorkey">
<big><b>pygame.surfarray.array_colorkey</big></b><br><ul>
  <i>Copy the colorkey values into a 2d array</i><br>
  <tt>pygame.surfarray.array_colorkey(Surface): return array</tt><br>
<p>Create a new array with the colorkey transparency value from each pixel. If the pixel matches the colorkey it will be fully tranparent; otherwise it will be fully opaque. </p>
<p>This will work on any type of Surface format. If the image has no colorkey a solid opaque array will be returned. </p>
<p>This function will temporarily lock the Surface as pixels are copied. </p>
<!--COMMENTS:pygame.surfarray.array_colorkey--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.make_surface">
<big><b>pygame.surfarray.make_surface</big></b><br><ul>
  <i>Copy an array to a new surface</i><br>
  <tt>pygame.surfarray.make_surface(array): return Surface</tt><br>
<p>Create a new Surface that best resembles the data and format on the array. The array can be <tt>2D</tt> or <tt>3D</tt> with any sized integer values. </p>
<!--COMMENTS:pygame.surfarray.make_surface--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.blit_array">
<big><b>pygame.surfarray.blit_array</big></b><br><ul>
  <i>Blit directly from a array values</i><br>
  <tt>pygame.surfarray.blit_array(Surface, array): return None</tt><br>
<p>Directly copy values from an array into a Surface. This is faster than converting the array into a Surface and blitting. The array must be the same dimensions as the Surface and will completely replace all pixel values. Only integer, ascii character and record arrays are accepted. </p>
<p>This function will temporarily lock the Surface as the new values are copied. </p>
<!--COMMENTS:pygame.surfarray.blit_array--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.map_array">
<big><b>pygame.surfarray.map_array</big></b><br><ul>
  <i>Map a 3d array into a 2d array</i><br>
  <tt>pygame.surfarray.map_array(Surface, array3d): return array2d</tt><br>
<p>Convert a <tt>3D</tt> array into a <tt>2D</tt> array. This will use the given Surface format to control the conversion. Palette surface formats are not supported. </p>
<!--COMMENTS:pygame.surfarray.map_array--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.use_arraytype">
<big><b>pygame.surfarray.use_arraytype</big></b><br><ul>
  <i>Sets the array system to be used for surface arrays</i><br>
  <tt>pygame.surfarray.use_arraytype (arraytype): return None</tt><br>
<p>Uses the requested array type for the module functions. Currently supported array types are: </p>
<pre>  numeric
  numpy
</pre><p>If the requested type is not available, a ValueError will be raised. </p>
<p>New in pygame <tt>1.8</tt>. </p>
<!--COMMENTS:pygame.surfarray.use_arraytype--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.get_arraytype">
<big><b>pygame.surfarray.get_arraytype</big></b><br><ul>
  <i>Gets the currently active array type.</i><br>
  <tt>pygame.surfarray.get_arraytype (): return str</tt><br>
<p>Returns the currently active array type. This will be a value of the get_arraytypes() tuple and indicates which type of array module is used for the array creation. </p>
<p>New in pygame <tt>1.8</tt> </p>
<!--COMMENTS:pygame.surfarray.get_arraytype--> &nbsp;<br> 
<br></ul>


<a name="pygame.surfarray.get_arraytypes">
<big><b>pygame.surfarray.get_arraytypes</big></b><br><ul>
  <i>Gets the array system types currently supported.</i><br>
  <tt>pygame.surfarray.get_arraytypes (): return tuple</tt><br>
<p>Checks, which array systems are available and returns them as a tuple of strings. The values of the tuple can be used directly in the <tt>pygame.surfarray.use_arraytype</tt> () method. If no supported array system could be found, None will be returned. </p>
<p>New in pygame <tt>1.8</tt>. </p>
<!--COMMENTS:pygame.surfarray.get_arraytypes--> &nbsp;<br> 
<br></ul>
<br></ul>

</body></html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.