0
votes

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??

1
You want to what? What is a GC of a xlib surface and what does it have to do with your queston? OoUli Schlachter
Graphics Context (GC of Xlib), I have to create imagesurface from it without loosing the content and data from the surface. thanks for revert Oo – Uli SchlachterNitish Nandwana

1 Answers

2
votes

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!) */