#include #include #include #include typedef struct { FILE *out; } png_stream_to_file_closure_t; static cairo_status_t write_png_stream_to_file(void *in_closure, const unsigned char *data, unsigned int length) { png_stream_to_file_closure_t *closure = (png_stream_to_file_closure_t *)in_closure; size_t wsize = fwrite((void *)data, length, 1, closure->out); return CAIRO_STATUS_SUCCESS; } int main() { cairo_surface_t *surf; cairo_t *cr; double width = 8000; double height = 8000; surf = cairo_svg_surface_create("foo.png", width, height); cr = cairo_create(surf); cairo_rectangle(cr, 10, 10, width-20, height-20); cairo_set_source_rgb(cr, 1.0, 0.5, 0.0); cairo_fill(cr); cairo_set_source_rgb(cr, 0.0, 1.0, 1.0); cairo_move_to(cr, 10.0, 10.0); cairo_line_to(cr, width-10, height-10); cairo_stroke(cr); png_stream_to_file_closure_t foo_closure; foo_closure.out = fopen("foo.png", "wb"); cairo_status_t status; status = cairo_surface_write_to_png_stream(surf, write_png_stream_to_file, &foo_closure); if (status != CAIRO_STATUS_SUCCESS) { printf("error writing png: %s\n", cairo_status_to_string(status)); } return 0; }