Lecture 8: Images and Surfaces in Pycairo Understanding surfaces, image handling, and exporting results.
What are Surfaces? - A Surface is the target for all drawing operations - Types: • ImageSurface (PNG raster images) • PDFSurface (PDF export) • SVGSurface (vector graphics) • Win32/XlibSurface (platform-specific)
Saving to Different Formats pdf_surface = cairo.PDFSurface('output.pdf', 400, 300) pdf_ctx = cairo.Context(pdf_surface) pdf_ctx.set_source_rgb(0, 0, 0) pdf_ctx.move_to(50, 50) pdf_ctx.show_text('Hello PDF!') pdf_surface.finish()
Summary - Surfaces are the target for all drawing - ImageSurface is most common for PNG output - You can load, scale, and combine images - Export drawings to PNG, PDF, or SVG