sudo apt-get install libcairo2-dev//pkg-config--cflags--libs cairo//-i/usr/include/cairo-i/usr/include/glib-2.0- I/usr/lib/x86_64-linux-gnu/glib-2.0/include-i/usr/include/pixman-1-i/usr/include/freetype2-i/usr/include/ libpng12 -lcairo#include <iostream> #include <cairo-svg.h> #define ANGLE (ANG) (ANG * 3.1415926/ 180.0) int Main (int argc, char **argv) { cairo_t *cr; cairo_surface_t *surface ; int cheight = Cwidth = cheight; Surface = (cairo_surface_t *) cairo_svg_surface _create ("Cairo_example.svg", Cheight, cwidth); cr = Cairo_create (surface); cairo_pattern_t *pattern; cairo_text_extents_t text; int x,y; //fill background black cairo_set_source_rgb (CR, 0, 0, 0 ); Cairo_rectangle (CR, 0, 0, cwidth, cheight); Cairo_fill (CR);// Cairo_set_source_rgb (CR, 0.5, 0.5, 0.5);// Pattern = cairo_pattern_create_radial (5,,);// Cairo_pattern_add_color_ Stop_rgb (pattern, 0, 0.75, 0.15, 0.99);// Cairo_pattern_add_color_stop_rgb (pattern, 0.9, 1, 1, 1);// Cairo_set_source (CR, pattern);// Cairo_fill (CR); /* Writing in the foreground */ cairo_set_font_size (CR, n); & nbsp; Cairo_select_font_face (CR, "Georgia", Cairo_font_slant_normal, Cairo_font_weight_bold); Cairo_set_source_rgb (CR, 0, 0, 1); cairo_move_to (CR, n); & nbsp Cairo_show_text (CR, "Hello"); cairo_move_to (CR, ten, page); Cairo_show_text (CR, " Wikipedia! "); CAIro_set_source_rgb (CR, 0, 1, 0); Cairo_set_antialias (CR, Cairo_antialias_good); Cairo_set_line_width (CR, 2); cairo_move_to (CR, 100, 80); cairo_line_to (CR ); Cairo_stroke (CR); cairo_move_to (CR, Max); Cairo_line_to (CR, +); Cairo_stroke (CR); Cairo_ rectangle_int_t rect; rect.x = 200; Rect.y = 200; Rect.width = 180 ; rect.height = 160; cairo_rectangle (CR, Rect.x, Rect.y, Rect.width, rect.height); Cairo_stroke (CR); //cairo_fill (CR); Cairo_set_source_rgba (CR, 1, 0, 1, 0.5); Cairo_set_line_width (CR, +); int cx =, cy = +, R = 130;   ; Cairo_arc (CR, CX, CY, R, ANGLE (0), ANGLE (360)); Cairo_stroke (CR); Cairo_surface_write_to_png ( Surface, "demo1.png"); Cairo_destroy (CR); Cairo_surface_ Destroy (surface); return 0;}
Compilation under Ubuntu:
g++ ' Pkg-config--cflags Cairo ' test_cairo.cpp ' Pkg-config--libs Cairo '
Note: The above symbol is not a single quote, but the key to the left of the ESC key on the keyboard and the!/1 key.
Operation Result:
C + + Cairo drawing graphics based on Vector graphics library