Loading an image into Pycairo

Before we look at the SurfacePattern, we will take a quick look at how we can load an image into Pycairo.

Surface provides a create_from_png class method that reads a PNG image from a file, creates a suitable surface, and fills the surface with the image pixels. Here is how it can be used:

Get hands-on with 1200+ tech skills courses.