Re: Draw in a GdkPixbuf
Thank you James, I found what I wanted in one of the links: http://live.gnome.org/GtkCairoIntegration I had previously seen this page, but didn't see a small code snippet in python that does what I want. I've translated it in C, and it work now: I can convert a pixbuf to something where I can draw in with cairo. For the curious ones, here's a simple example on how to do that. Thanks again, -- Luis #include glib.h #include cairo.h #include gdk-pixbuf/gdk-pixbuf.h int main (void) { GdkPixbuf *pixbuf; gint width, height; cairo_format_t format; cairo_surface_t *surface; cairo_t *cr; g_type_init (); pixbuf = gdk_pixbuf_new_from_file (test.png, NULL); g_assert (pixbuf != NULL); format = (gdk_pixbuf_get_has_alpha (pixbuf)) ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24; width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); surface = cairo_image_surface_create (format, width, height); g_assert (surface != NULL); cr = cairo_create (surface); /* Draw the pixbuf */ gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); cairo_paint (cr); /* Draw a red rectangle */ cairo_set_source_rgb (cr, 1, 0, 0); cairo_rectangle (cr, width * .25, height * .25, width *.5, height *.5); cairo_fill (cr); /* Save to a PNG file */ cairo_surface_write_to_png (surface, output.png); cairo_surface_destroy (surface); cairo_destroy (cr); return 0; } James Scott Jr a écrit : Ok, http://cairographics.org/examples/ http://live.gnome.org/GtkCairoIntegration These links have some examples of using everything from a raw image to a pdf as the backend in cairo from the command line -- without the use of gtk. Hope this fits your need better than my last response. James, On Thu, 2008-05-29 at 03:18 +0200, Luis Menina wrote: Hi list! I'm trying to find a way to draw in a GdkPixbuf (for example draw a rectangle on the pixbuf) and save the result to a file afterwards. I found in devhelp the gdk_draw_* functions, but to use them I need a GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that I'm developping a command line application, so I don't use GTK, only glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL GdkDrawable, I can't workaround the problem, because the documentation of gdk_draw_pixbuf tells me that All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap(). Trying to get a colormap requires other stuff, which requires other stuff, and so on... As this seems to be quite old-fashioned way of doing things, I tried to see if cairo could do the trick. But it seems there's no way to draw to a GdkPixbuf with cairo (I'm unfamiliar with cairo). So, does anyone have an hint on how to draw and save an image from a GdkPixbuf, with gdk or cairo ? Thanks for you help, Luis ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Draw in a GdkPixbuf
Thanks for your advice. Unfortunately, this doesn't help here, since all the examples you cite use GTK, so they don't have the same problem, as they draw on existing drawables. What I want is drawing on an image that will not be rendered on screen. So I have no graphical context, just a GdkPixbuf as an input, and I want to modify that image to save it in a file. There's no problem for me if I don't work directly on the GdkPixbuf: something that will convert the GdkPixbuf into somethins else that I can draw on is an acceptable solution. Cheers, Luis James Scott Jr a écrit : Take a look at the executable 'gtk-demo'. It should have been installed with gtk's development tools; i.e. already loaded on you machine. Hint: double click the sample for a live preview, then look at the source code. Additionally, here is a link to glinegraph, a simple line graph widget written twice, once in gdk and again in cairo. http://sourceforge.net/project/showfiles.php?group_id=157888package_id=191712 James, On Thu, 2008-05-29 at 03:18 +0200, Luis Menina wrote: Hi list! I'm trying to find a way to draw in a GdkPixbuf (for example draw a rectangle on the pixbuf) and save the result to a file afterwards. I found in devhelp the gdk_draw_* functions, but to use them I need a GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that I'm developping a command line application, so I don't use GTK, only glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL GdkDrawable, I can't workaround the problem, because the documentation of gdk_draw_pixbuf tells me that All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap(). Trying to get a colormap requires other stuff, which requires other stuff, and so on... As this seems to be quite old-fashioned way of doing things, I tried to see if cairo could do the trick. But it seems there's no way to draw to a GdkPixbuf with cairo (I'm unfamiliar with cairo). So, does anyone have an hint on how to draw and save an image from a GdkPixbuf, with gdk or cairo ? Thanks for you help, Luis ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Draw in a GdkPixbuf
Ok, http://cairographics.org/examples/ http://live.gnome.org/GtkCairoIntegration These links have some examples of using everything from a raw image to a pdf as the backend in cairo from the command line -- without the use of gtk. Hope this fits your need better than my last response. James, On Thu, 2008-05-29 at 03:18 +0200, Luis Menina wrote: Hi list! I'm trying to find a way to draw in a GdkPixbuf (for example draw a rectangle on the pixbuf) and save the result to a file afterwards. I found in devhelp the gdk_draw_* functions, but to use them I need a GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that I'm developping a command line application, so I don't use GTK, only glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL GdkDrawable, I can't workaround the problem, because the documentation of gdk_draw_pixbuf tells me that All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap(). Trying to get a colormap requires other stuff, which requires other stuff, and so on... As this seems to be quite old-fashioned way of doing things, I tried to see if cairo could do the trick. But it seems there's no way to draw to a GdkPixbuf with cairo (I'm unfamiliar with cairo). So, does anyone have an hint on how to draw and save an image from a GdkPixbuf, with gdk or cairo ? Thanks for you help, Luis ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Draw in a GdkPixbuf
Hi list! I'm trying to find a way to draw in a GdkPixbuf (for example draw a rectangle on the pixbuf) and save the result to a file afterwards. I found in devhelp the gdk_draw_* functions, but to use them I need a GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that I'm developping a command line application, so I don't use GTK, only glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL GdkDrawable, I can't workaround the problem, because the documentation of gdk_draw_pixbuf tells me that All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap(). Trying to get a colormap requires other stuff, which requires other stuff, and so on... As this seems to be quite old-fashioned way of doing things, I tried to see if cairo could do the trick. But it seems there's no way to draw to a GdkPixbuf with cairo (I'm unfamiliar with cairo). So, does anyone have an hint on how to draw and save an image from a GdkPixbuf, with gdk or cairo ? Thanks for you help, Luis ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Draw in a GdkPixbuf
Take a look at the executable 'gtk-demo'. It should have been installed with gtk's development tools; i.e. already loaded on you machine. Hint: double click the sample for a live preview, then look at the source code. Additionally, here is a link to glinegraph, a simple line graph widget written twice, once in gdk and again in cairo. http://sourceforge.net/project/showfiles.php?group_id=157888package_id=191712 James, On Thu, 2008-05-29 at 03:18 +0200, Luis Menina wrote: Hi list! I'm trying to find a way to draw in a GdkPixbuf (for example draw a rectangle on the pixbuf) and save the result to a file afterwards. I found in devhelp the gdk_draw_* functions, but to use them I need a GdkPixmap. gdk_pixmap_new requires a GdkDrawable. The problem is that I'm developping a command line application, so I don't use GTK, only glib, gdk, and gdk-pixbuf. Even creating the GdkPixmap with a NULL GdkDrawable, I can't workaround the problem, because the documentation of gdk_draw_pixbuf tells me that All windows have a colormap, however, pixmaps only have colormap by default if they were created with a non-NULL window argument. Otherwise a colormap must be set on them with gdk_drawable_set_colormap(). Trying to get a colormap requires other stuff, which requires other stuff, and so on... As this seems to be quite old-fashioned way of doing things, I tried to see if cairo could do the trick. But it seems there's no way to draw to a GdkPixbuf with cairo (I'm unfamiliar with cairo). So, does anyone have an hint on how to draw and save an image from a GdkPixbuf, with gdk or cairo ? Thanks for you help, Luis ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list