How to draw a sliced image in Cairo?
Posted
by
Maz
on Stack Overflow
See other posts from Stack Overflow
or by Maz
Published on 2011-11-13T17:46:47Z
Indexed on
2011/11/13
17:50 UTC
Read the original article
Hit count: 299
I am currently using the following code to draw sliced images:
static void DrawImage(cairo_t *ctx,int x,int y,int w,int h,cairo_surface_t *img){
cairo_set_source_surface(ctx, img, 0, 0);
cairo_rectangle(ctx, x, y, w, h);
cairo_clip(ctx);
cairo_paint(ctx);
cairo_reset_clip(ctx);
}
void DrawThreeSliceImage(cairo_t* ctx,Point p,int width,cairo_surface_t *a,cairo_surface_t *b,cairo_surface_t *c){
DrawImage(ctx, p.x, p.y, cairo_image_surface_get_width(a), cairo_image_surface_get_height(a),a);
DrawImage(ctx, p.x+cairo_image_surface_get_width(a), p.y, width-(cairo_image_surface_get_width(a)+cairo_image_surface_get_width(c)), cairo_image_surface_get_height(b),b);
DrawImage(ctx, p.x+(width-cairo_image_surface_get_width(c)), p.y, cairo_image_surface_get_width(c), cairo_image_surface_get_height(c),c);
}
However, there is no output. I have tried rendering to both xlib and png surfaces, neither seems to work, that is nothing is drawn. Also, I have written the input surfaces to png files, and they appear to be working.
Thanks.
© Stack Overflow or respective owner