Working with Images
Explore how to load PNG images into Pycairo and use them as SurfacePatterns. Learn techniques to transform images by scaling and translating, and apply tiling effects with extend modes to create versatile vector graphic fills.
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:
This code reads in a PNG file called tiger.png, but we can use any PNG image. The newly-created surface, called image, is queried for size and format. The image is 400 by 400 pixels, which the code above will print when ...