
/* cairo036.c 剪切图片内容 */
#include <cairo.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
static cairo_surface_t *surface = NULL;
struct df_canvas
{
char filename[28];
int type;
double width;
double height;
};
void df_draw_brush (struct df_canvas const *pcanvas)
{
cairo_surface_t* image;
cairo_t *cr;
cr = cairo_create (surface);
cairo_arc (cr, 300.0, 300.0, 150.0, 0, 2 * M_PI);
cairo_clip (cr); /* 以上内容做剪切路径 */
cairo_new_path (cr);
image = cairo_image_surface_create_from_png ("star.png"); /* 读取图片内容 */
cairo_scale (cr, 1.1, 1.1);
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);
cairo_surface_write_to_png (surface, pcanvas -> filename);
cairo_destroy (cr);
}
void df_init_canvas (struct df_canvas const *pcanvas)
{
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, (int) pcanvas -> width, (int) pcanvas -> height);
}
int main (int argc, char *argv[])
{
struct df_canvas *canvas;
canvas = (struct df_canvas*) malloc (sizeof (struct df_canvas));
strncpy(canvas -> filename, "hello.png", 28);
canvas -> type = CAIRO_SURFACE_TYPE_IMAGE;
canvas -> width = 600.0;
canvas -> height = 600.0;
df_init_canvas (canvas);
df_draw_brush (canvas);
free (canvas);
if (surface != NULL) cairo_surface_destroy (surface);
return 0;
}






