using Cairo; // Create a new surface and a Cairo context Surface surface = new ImageSurface(Format.Argb32, 100, 100); Context context = new Context(surface); // Set the fill color to red using SetSource context.SetSourceRGB(1.0, 0.0, 0.0); // Draw a rectangle with red fill color context.Rectangle(0, 0, 100, 100); context.Fill(); // Dispose objects context.Dispose(); surface.Dispose();
using Cairo; // Create a new surface and a Cairo context Surface surface = new ImageSurface(Format.Argb32, 100, 100); Context context = new Context(surface); // Create a linear gradient from top to bottom LinearGradient gradient = new LinearGradient(0, 0, 0, 100); gradient.AddColorStopRGB(0, 1.0, 0.0, 0.0); gradient.AddColorStopRGB(1, 0.0, 0.0, 1.0); // Set the gradient as the source using SetSource context.SetSource(gradient); // Draw a rectangle with gradient fill context.Rectangle(0, 0, 100, 100); context.Fill(); // Dispose objects gradient.Dispose(); context.Dispose(); surface.Dispose();These examples make use of the Cairo library bindings for C#, which are provided by the Mono.Cairo package library.