Reputation: 9
Can You Please Help me out in this issue as i want to create an image from GC of cairo xlib's surface using cairo and x11 api's??
Upvotes: 0
Views: 604
Reputation: 9867
I am still not sure that I really understand your question, but let's try:
You have a cairo X11 surface called x11_surf
and want to get the contents of that into a new image surface called img_surf
:
double x1, y1, x2, y2;
cairo_t *cr;
cairo_surface_t *img_surf;
/* Figure out the size of the x11 surface */
cr = cairo_create(x11_surf);
cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
cairo_destroy(cr);
/* Allocate an image surface of a suitable size */
img_surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, x2, y2);
/* Copy the contents over */
cr = cairo_create(img_surf);
cairo_set_source_surface(cr, x11_surf, 0, 0);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_paint(cr);
cairo_destroy(cr);
/* Done (Notice that nothing needed a GC here!) */
Upvotes: 2