2
<title>pygame.surfarray</title>
3
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
6
<table cellspacing=3 width=100%><tr><td bgcolor=#00000>
7
<table width=100%><tr><td bgcolor=c2fc20 align=center>
8
<a href=http://www.pygame.org>
9
<img src=../pygame_tiny.gif border=0 width=200 height=60></a><br>
10
<b>pygame documentation</b>
11
</td><td bgcolor=6aee28 align=center valign=top width=100%>
14
<a href=http://www.pygame.org>Home</a> ||
15
<a href=../index.html>Help Contents</a> ||
18
|| <a href=pygame.html>pygame</a> ||
19
<a href=pygame_cdrom.html>cdrom</a> ||
20
<a href=pygame_constants.html>constants</a> ||
21
<a href=pygame_display.html>display</a> ||
22
<a href=pygame_draw.html>draw</a> ||
23
<a href=pygame_event.html>event</a> ||<br>
24
|| <a href=pygame_font.html>font</a> ||
25
<a href=pygame_image.html>image</a> ||
26
<a href=pygame_joystick.html>joystick</a> ||
27
<a href=pygame_key.html>key</a> ||
28
<a href=pygame_mixer.html>mixer</a> ||
29
<a href=pygame_mixer_music.html>mixer_music</a> ||<br>
30
|| <a href=pygame_mouse.html>mouse</a> ||
31
<a href=pygame_movie.html>movie</a> ||
32
<a href=pygame_surfarray.html>surfarray</a> ||
33
<a href=pygame_time.html>time</a> ||
34
<a href=pygame_transform.html>transform</a> ||<br>
35
<br>|| <a href=CD.html>CD</a> ||
36
<a href=Channel.html>Channel</a> ||
37
<a href=Clock.html>Clock</a> ||
38
<a href=Font.html>Font</a> ||
39
<a href=Joystick.html>Joystick</a> ||
40
<a href=Movie.html>Movie</a> ||<br>
41
|| <a href=Rect.html>Rect</a> ||
42
<a href=Sound.html>Sound</a> ||
43
<a href=Surface.html>Surface</a> ||<br>
44
<br>|| <a href=pygame_cursors.html>cursors</a> ||
45
<a href=pygame_sprite.html>sprite</a> ||
46
<a href=pygame_version.html>version</a> ||<br>
49
</td></tr></table></td></tr></table>
51
<h2 align=center>pygame.surfarray</h2>
52
Contains routines for mixing numeric arrays with
58
<tr><td><a href=#array2d>array2d</a></td><td> -
59
get a 2d array copied from a surface</td></tr>
62
<tr><td><a href=#array3d>array3d</a></td><td> -
63
get a 3d array copied from a surface</td></tr>
66
<tr><td><a href=#array_alpha>array_alpha</a></td><td> -
67
get an array with a surface pixel alpha values</td></tr>
70
<tr><td><a href=#array_colorkey>array_colorkey</a></td><td> -
71
get an array with a surface colorkey values</td></tr>
74
<tr><td><a href=#blit_array>blit_array</a></td><td> -
75
quickly transfer an array to a Surface</td></tr>
78
<tr><td><a href=#map_array>map_array</a></td><td> -
79
map an array with RGB values into mapped colors</td></tr>
82
<tr><td><a href=#pixels2d>pixels2d</a></td><td> -
83
get a 2d reference array to a surface</td></tr>
86
<tr><td><a href=#pixels3d>pixels3d</a></td><td> -
87
get a 3d reference array to a surface</td></tr>
90
<tr><td><a href=#pixels_alpha>pixels_alpha</a></td><td> -
91
get a reference array to a surface alpha data</td></tr>
98
<a name=array2d><font size=+2><b>array2d
99
</b></font><br><font size=+1><tt>
100
pygame.surfarray.array2d(Surface) -> Array
102
This returns a new contigous 2d array. Think of it
103
as a 2d image array with a mapped pixel value at
106
This function will temporarily lock the surface.
109
<a name=array3d><font size=+2><b>array3d
110
</b></font><br><font size=+1><tt>
111
pygame.surfarray.array3d(Surface) -> Array
113
This returns a new contigous 3d array. Think of it
114
as a 2d image array with an RGB array for each
117
This function will temporarily lock the surface.
120
<a name=array_alpha><font size=+2><b>array_alpha
121
</b></font><br><font size=+1><tt>
122
pygame.surfarray.array_alpha(Surface) -> Array
124
This returns a new contigous 2d array with the
125
alpha values of an image as unsigned bytes. If the
126
surface has no alpha, an array of all opaque values
129
This function will temporarily lock the surface.
132
<a name=array_colorkey><font size=+2><b>array_colorkey
133
</b></font><br><font size=+1><tt>
134
pygame.surfarray.array_colorkey(Surface) -> Array
136
This returns a new contigous 2d array with the
137
colorkey values of an image as unsigned bytes. If the
138
surface has no colorkey, an array of all opaque values
139
is returned. Otherwise the array is either 0's or 255's.
141
This function will temporarily lock the surface.
144
<a name=blit_array><font size=+2><b>blit_array
145
</b></font><br><font size=+1><tt>
146
pygame.surfarray.blit_array(surf, array) -> None
148
Transfer an array of any type (3d or 2d) onto a
149
Surface. The array must be the same dimensions as
150
the destination Surface. While you can assign the
151
values of an array to the pixel referenced arrays,
152
using this blit method will usually be quicker
153
because of it's smarter handling of noncontiguous
154
arrays. Plus it allows you to blit from any image
155
array type to any surface format in one step, no
156
internal conversions.
158
This function will temporarily lock the surface.
161
<a name=map_array><font size=+2><b>map_array
162
</b></font><br><font size=+1><tt>
163
pygame.surfarray.map_array(surf, array3d) -> array2d
165
Create a new array with the RGB pixel values of a
166
3d array into mapped color values in a 2D array.
168
Just so you know, this can also map a 2D array
169
with RGB values into a 1D array of mapped color
173
<a name=pixels2d><font size=+2><b>pixels2d
174
</b></font><br><font size=+1><tt>
175
pygame.surfarray.pixels2d(Surface) -> Array
177
This returns a new noncontigous 2d array that
178
directly effects a Surface's contents. Think of it
179
as a 2d image array with a mapped pixel value at
182
This will not work on 24bit surfaces, since there
183
is no native 24bit data type to access the pixel
186
This function will lock the given surface, and it
187
will remained locked for as long as the pixel array
191
<a name=pixels3d><font size=+2><b>pixels3d
192
</b></font><br><font size=+1><tt>
193
pygame.surfarray.pixels3d(Surface) -> Array
195
This returns a new noncontigous 3d array that
196
directly effects a Surface's contents. Think of it
197
as a 2d image array with an RGB array for each
200
This will only work for 24 and 32 bit surfaces,
201
where the RGB components can be accessed as 8-bit
204
This function will lock the given surface, and it
205
will remained locked for as long as the pixel array
209
<a name=pixels_alpha><font size=+2><b>pixels_alpha
210
</b></font><br><font size=+1><tt>
211
pygame.surfarray.pixels_alpha(Surface) -> Array
213
This returns a new noncontigous array that directly
214
effects a Surface's alpha contents.
216
This will only work for 32bit surfaces with a pixel
217
alpha channel enabled.
219
This function will lock the given surface, and it
220
will remained locked for as long as the pixel array