Cairo 庫繪圖
  Cairo 是一(yi)個用(yong) C 編(bian)程語(yu)言(yan)編(bian)寫的用(yong)于創建 2D 矢量圖形(xing)的庫。
Cairo繪圖模型
- Source
繪圖目(mu)標區。
-  Mask
 遮罩,在將源應用于表面之前,先對其進行過濾。 遮罩用作過濾器。 遮罩確定在哪里應用源,在哪里不應用。 遮罩的不透明部分允許復制 源。透明零件不允許將源復制到表面。
- Path
 繪制的虛擬路徑,可以是一條線段,閉合四邊形或者其他曲線。路徑可以由直線和曲線組成。 路徑有兩種。 打開和關閉路徑。 在封閉的路徑 中,起點和終點相遇。 在開放路徑中,起點和終點不相交。
- Conext  
 在Cairo中繪制都是通過Context的,該變量持有所有圖形樣式繪圖變量,比如縣寬度、顏色及surface等。所有Cario所繪制的變量的結構叫做 cairo_t對象,可以繪制在PDF、SVG、PNG及GtkWindow上。
- Surface
 Cairo繪制的目標區域,使用cario_surface_t表示。
Cario簡單使用
#include <cairo/cairo.h>
int main(void)
{
  cairo_surface_t *surface;
  cairo_t *cr;
//從test.png創建surface
  surface = cairo_image_surface_create_from_png("test.png");  
  cr = cairo_create(surface);
  cairo_set_source_rgb(cr, 2, 2, 255);
//設置字體
  cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
      CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 40.0);
//獲取寬高
  int width = cairo_image_surface_get_width (surface);
  int height = cairo_image_surface_get_height (surface);
  printf("with=%d, height=%d \n.", width, height);  
//移動到畫布中間
  cairo_move_to(cr, width/2, height/2);
//順時針旋轉 30°
  cairo_rotate(cr, 3.14 * 30 / 180); 
//顯示繪制字體
  cairo_show_text(cr, "Cairo Cairo Cairo .");
//生成帶文字的圖片
  cairo_surface_write_to_png(surface, "test1.png");
//資源銷毀
  cairo_destroy(cr);
  cairo_surface_destroy(surface);
  return 0;
}
編譯&運行
gcc -o carotest carotest.c -l cairo
./carotest查看效果
原圖:

生成:

參考資料:
//www.kancloud.cn/apachecn/zetcode-zh/1950067
//www.cairographics.org/tutorial/