ipygame.surfarray
pygame-compatible surfarray module.
array2d
Section titled “array2d”def array2d(surface: Surface) -> np.ndarrayCopy pixel data as a 2D array of mapped colors (uint32).
pixels2d
Section titled “pixels2d”def pixels2d(surface: Surface) -> np.ndarrayReturn a 2D reference to surface pixels (copy — true sharing not possible).
array3d
Section titled “array3d”def array3d(surface: Surface) -> np.ndarrayCopy RGB data as a (H,W,3) array.
pixels3d
Section titled “pixels3d”def pixels3d(surface: Surface) -> np.ndarrayReturn a (H,W,3) view into the surface’s RGB channels.
Modifications to the returned array will modify the surface.
array_alpha
Section titled “array_alpha”def array_alpha(surface: Surface) -> np.ndarrayCopy alpha channel as a (H,W) array.
pixels_alpha
Section titled “pixels_alpha”def pixels_alpha(surface: Surface) -> np.ndarrayReturn a view into the surface’s alpha channel.
array_red
Section titled “array_red”def array_red(surface: Surface) -> np.ndarraypixels_red
Section titled “pixels_red”def pixels_red(surface: Surface) -> np.ndarrayarray_green
Section titled “array_green”def array_green(surface: Surface) -> np.ndarraypixels_green
Section titled “pixels_green”def pixels_green(surface: Surface) -> np.ndarrayarray_blue
Section titled “array_blue”def array_blue(surface: Surface) -> np.ndarraypixels_blue
Section titled “pixels_blue”def pixels_blue(surface: Surface) -> np.ndarrayarray_colorkey
Section titled “array_colorkey”def array_colorkey(surface: Surface) -> np.ndarrayReturn a 2D array where colorkey-pixels are 0, others 255.
make_surface
Section titled “make_surface”def make_surface(array: np.ndarray) -> SurfaceCreate a new Surface from a numpy array.
Accepts (H,W,3) RGB, (H,W,4) RGBA, or (H,W) mapped uint32.
blit_array
Section titled “blit_array”def blit_array(surface: Surface, array: np.ndarray) -> NoneBlit an array directly onto a surface.
map_array
Section titled “map_array”def map_array(surface: Surface, array: np.ndarray) -> np.ndarrayMap a (H,W,3) RGB array to a (H,W) mapped-pixel array.
surface_to_array
Section titled “surface_to_array”def surface_to_array(array: np.ndarray, surface: Surface, kind: str = "P", opaque: int = 255, clear: int = 0) -> NoneCopy surface pixels into an existing array.
array_to_surface
Section titled “array_to_surface”def array_to_surface(surface: Surface, array: np.ndarray) -> NoneCopy an array into a surface.