GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Apr 20, 2014 12:54 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: cairo recording surface leaves target surface empty
PostPosted: Thu Oct 13, 2011 10:50 pm 
Offline

Joined: Tue Jul 19, 2011 4:09 pm
Posts: 2
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;
}


Top
 Profile  
 
 Post subject: Re: cairo recording surface leaves target surface empty
PostPosted: Wed Oct 19, 2011 1:20 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

Not sure why things are not woring here (I tested your app and got exactly the same results). I learned that using a constrained surface does produce a file, so the problem is either with unconstrained surface or it's placement when using it as a source for painting.

Cheers,
Tadej


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group