Debian Codegraph @

docs/tutorial/numpy.rst

raw
1 Integration with NumPy
2 ======================
3
4 https://numpy.org/
5
6 NumPy & ImageSurface
7 --------------------
8
9 Creating an ImageSurface from a NumPy array:
10
11 .. code:: python
12
13 import numpy
14 import cairo
15
16 width, height = 255, 255
17 data = numpy.ndarray(shape=(height, width), dtype=numpy.uint32)
18 surface = cairo.ImageSurface.create_for_data(
19 data, cairo.FORMAT_ARGB32, width, height)
20
21 Creating a NumPy array from an ImageSurface:
22
23 .. code:: python
24
25 import numpy
26 import cairo
27
28 width, height = 255, 255
29 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
30 buf = surface.get_data()
31 data = numpy.ndarray(shape=(height, width),
32 dtype=numpy.uint32,
33 buffer=buf)