Saving a gnomecanvas to a .png (or other graphic format)
- From: Steve Field <sfield98 yahoo com>
- To: gnome-devel-list gnome org
- Subject: Saving a gnomecanvas to a .png (or other graphic format)
- Date: Sat, 12 Mar 2005 23:09:14 -0800 (PST)
I have been successfully (for the most part) been
using gnomecanvas to do a flight sim instrumentation
type display. What I'd eventually like to do is make a
demo movie of the display.
To that end, I've been trying to dump any updated
gnomecanvas to a .png file for later manipulation into
a .mng or animated .gif or mpeg file. To date, I've
been unsuccessful.
I dug into the list archives and found a post that
seemed to indicate that I could copy the code from
gnome_canvas_paint_rect to copy the gnomecanvas into a
pixmap which could then be copied into a pixbuf for
.png saving. I dutifully copied code and got a .png
file that's the right size, but might have the wrong
depth since the colored portion of the resulting .png
looks like a smeared and shortened version of the
original gnomecanvas.
I added the following code to the end of my
gnomecanvas update routine (canvas2 is a pointer to
the GnomeCanvas of interest):
{
GnomeCanvas *canvas = GNOME_CANVAS(canvas2);
GtkWidget *widget = GTK_WIDGET(canvas2);
GError *gerror = NULL;
// Make a temporary pixbuf
GdkPixbuf *pb = NULL;
// Make the "temporary" pixmap
GdkPixmap *p = gdk_pixmap_new
(canvas->layout.bin_window,
widget->allocation.width,
widget->allocation.height,
gtk_widget_get_visual (widget)->depth);
// Draw the root canvas item to the pixmap
GdkDrawable
(*GNOME_CANVAS_ITEM_GET_CLASS(canvas->root)->draw)
(GNOME_CANVAS_ITEM(canvas->root),
GDK_DRAWABLE(p),
0,0,
widget->allocation.width,
widget->allocation.height);
// Now put the pixmap into a pixbuf
pb = gdk_pixbuf_get_from_drawable(NULL,
p, NULL,
0,0,
0,0,
-1,-1);
if(pb==NULL){
g_print("Problem rendering from the
pixmap into the pixbuf\n");
}else{
if(!gdk_pixbuf_save(pb,
"blah.png",
"png",
&gerror,
NULL)){
g_print("Problem saving the pixmap to
a .png file\n");
}
}
}
BTW, thanks to Mr. Pennington for his excellent GGAD
which got me this far!
Thanks for any thoughts or ideas!
Steve Field
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]