File: numpy.rst

package info (click to toggle)
pycairo 1.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,984 kB
  • sloc: ansic: 8,873; python: 3,688; makefile: 32; sh: 4
file content (33 lines) | stat: -rw-r--r-- 769 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
Integration with NumPy
======================

https://numpy.org/

NumPy & ImageSurface
--------------------

Creating an ImageSurface from a NumPy array:

.. code:: python

    import numpy
    import cairo

    width, height = 255, 255
    data = numpy.ndarray(shape=(height, width), dtype=numpy.uint32)
    surface = cairo.ImageSurface.create_for_data(
        data, cairo.FORMAT_ARGB32, width, height)

Creating a NumPy array from an ImageSurface:

.. code:: python

    import numpy
    import cairo

    width, height = 255, 255
    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    buf = surface.get_data()
    data = numpy.ndarray(shape=(height, width),
                            dtype=numpy.uint32,
                            buffer=buf)