Hi folks,
I try to use the recording surface of cairo. But when I draw it onto another surface, there's nothing.
What's wrong here? Im new to cairo. So it's going to be a stupid mistake. :-P
Code:
#include <stdlib.h>
#include <stdio.h>
#include <cairo/cairo.h>
int main(void)
{
cairo_surface_t *record = cairo_recording_surface_create(CAIRO_CONTENT_COLOR, NULL);
cairo_t *record_cr = cairo_create(record);
cairo_set_source_rgb(record_cr, 1, 0, 0);
cairo_rectangle(record_cr, 10, 10, 100, 100);
cairo_fill(record_cr);
cairo_set_source_rgb(record_cr, 0, 1, 0);
cairo_rectangle(record_cr, 50, 50, 140, 140);
cairo_fill(record_cr);
double x0, y0, width, height;
cairo_recording_surface_ink_extents(record, &x0, &y0, &width, &height);
cairo_surface_t *output = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(output);
cairo_set_source_surface(cr, record, 0, 0);
cairo_paint(cr);
cairo_surface_write_to_png(output, "out.png");
cairo_destroy(record_cr);
cairo_destroy(cr);
cairo_surface_destroy(record);
cairo_surface_destroy(output);
return EXIT_SUCCESS;
}