Reputation: 531
How do you save the contents of a gtk_drawing_area or cairo context to disk?
similar to this (Python) question: Save the contents of a Gtk.DrawingArea or Cairo pattern to an image on disk
but in C.
Upvotes: 1
Views: 396
Reputation: 11588
The Python code you linked doesn't seem to do anything different from what a C program would do; you would just need to look up the equivalent C methods, like gdk_pixbuf_savev()
.
However, because your original question said cairo pattern*, I supposed you deduced that since you write the implementation of the GtkDrawingArea draw
signal handler, you could reuse that code to draw to an image. You're correct.
In that case, you would first create an image surface and then a cairo_t
from that surface. Pass that to your drawing function, and then you can save the surface to a PNG. Here's an example (from the Pango documentation).
Of course, this assumes your draw
handler is written such that it doesn't use either the GtkDrawingArea or the data
parameter. If it does, you'll need to split the actual drawing logic out. Either way, hope that helps!
*I'm assuming you meant cairo context or cairo surface. A pattern is just a definition for how a drawing operation draws; saving that to an image is somewhat meaningless. (You can create patterns out of images, yes, but that still doesn't mean much for saving.)
Upvotes: 1