Numpy Integration
Explore how to integrate Pycairo with NumPy by creating arrays from image surfaces and constructing surfaces from NumPy arrays. Understand techniques for manipulating pixel data to generate complex vector graphics and write output files.
We'll cover the following...
We'll cover the following...
Creating a numpy array from a surface
We can create a numpy array from an ImageSurface like this:
We create our red square image in the same way that we did in the Pillow example. Then, we obtain the data using the get_data function. There is no need to convert the data to a byte buffer, because numpy understands memoryview objects.
We ...