Re: GdkPixbuf query



This really isn't the right list for this sort of question. Either
gnome-devel-list or gtk-app-list I think are correct.

> ** CRITICAL **: file gdk-pixbuf-render.c:
> line 209 (gdk_pixbuf_render_to_drawable):
> assertion `src_x >= 0 && src_x + width <= pixbuf->width' failed.

You are passing x = 1, and width = pixbuf_width, so x + width >
pixbuf->width.
Either you need to pass x = 0 and pixbuf_width or x = 1 and pixbuf_width
- 1.

> Is it valid to pass the GtkDrawingArea as a drwabale to the
> gdk_pixbuf_render_to_drawable function?

No, you should pass GTK_WIDGET (widget)->window


> Finally, are there any websites where I could look at some example code
> of loading/displaying images using this library?

Here's a program I've just written that *should* do it. I've not tested
it so there's probably some really stupid error in it, but I think it's
generally the right way to do things (fingers crossed).

There's a further (more complicated but much much cooler) demo in the
gdk-pixbuf/demo directory. Actually, everyone should run this demo once
a day, cos it's just so cool.

/* Fun program to display the image "nique.png" in a window 
   Public Domain: Use it as you feel like. */
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

GdkPixbuf *pixbuf;

static int 
event  (GtkDrawingArea *area,
	GdkEventExpose *ev,
	gpointer userdata)
{
	GdkGC *gc;

	gc = gdk_gc_new (GTK_WIDGET (area)->window);
	/* Draw to the window. Your code was doing 1, 1, 1, 1 and width 
		of the pixbuf, but it should have either been 0, 0, 0 ,0 		or width of
pixbuf - 1.
	*/
	gdk_pixbuf_render_to_drawable  (pixbuf, 
					GTK_WIDGET (area)->window, gc, 					0, 0,
					0, 0, 
					gdk_pixbuf_get_width (pixbuf),
					gdk_pixbuf_get_height (pixbuf),
					GDK_RGB_DITHER_NONE, 0, 0);
	/* Unref the GC so we don't have a memory leak */
	gdk_gc_unref (gc);
}

/* Unref the pixbuf when we're done:
   Technically not needed as we're quiting right afterwards,
   but done just for completeness. */
static void
destroy_event  (GtkWidget *widget,
		gpointer userdata)
{
	gdk_pixbuf_unref (pixbuf);
	gtk_main_quit ();
}

/* Fairly standard program main */
int
main (int argc,
      char **argv)
{
	GtkWidget *drawing_area, *window;

	gtk_init (&argc, &argv);
	gdk_rgb_init ();

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_signal_connect (GTK_OBJECT (window), "destroy",
			    GTK_SIGNAL_FUNC (destroy_event), NULL);

	drawing_area = gtk_drawing_area_new ();
	gtk_container_add (GTK_CONTAINER (window), drawing_area);
	gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
			    GTK_SIGNAL_FUNC (event), NULL);

	pixbuf = gdk_pixbuf_new_from_file ("nique.png");
	g_return_val_if_fail (pixbuf != NULL, 1);

	gtk_drawing_area_size  (GTK_DRAWING_AREA (drawing_area),
gdk_pixbuf_get_width (pixbuf),
				gdk_pixbuf_get_height (pixbuf));
	gtk_widget_show_all (window);

	gtk_main ();
}






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]