Re: Saving a gnomecanvas to a .png (or other graphic format)
- From: Jean Bréfort <jean brefort normalesup org>
- To: Steve Field <sfield98 yahoo com>
- Cc: gnome-devel-list gnome org
- Subject: Re: Saving a gnomecanvas to a .png (or other graphic format)
- Date: Thu, 17 Mar 2005 13:23:18 +0100
Le samedi 12 mars 2005 �3:09 -0800, Steve Field a �it :
> 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
I do that in GChemPaint to draw a GnomeCanvasGroup to a pixbuf:
GnomeCanvasGroup *group;
ArtDRect rect;
...
/* initialize group to canvas->root or another group and rect to the
area you want to draw */
...
GdkPixbuf *pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, w, h);
GnomeCanvasBuf buf;
buf.buf = gdk_pixbuf_get_pixels (pixbuf);
buf.rect.x0 = (int) floor (rect.x0);
buf.rect.x1 = (int) ceil (rect.x1);
buf.rect.y0 = (int) floor (rect.y0);
buf.rect.y1 = (int) ceil (rect.y1);
buf.buf_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
buf.bg_color = 0xffffff;
buf.is_buf = 1;
(* GNOME_CANVAS_ITEM_GET_CLASS (group)->render) (GNOME_CANVAS_ITEM
(group), &buf);
gdk_pixbuf_save (pixbuf, filename, type, NULL, NULL);
g_object_unref (pixbuf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]