Re: gdk-pix(buf|map) problem



>  I have a function that loads an image then draws it to a pixmap and a
>  bitmap, which are returned.
>  The problem is that if I make a pixmap with a depth more than 1, it gives me
>  BadValue and BadMatch errors.
>  The essence of the function is :
>  void
>  gum_load_image (gchar *filename,
>                                GdkPixmap **pmap,
>                                GdkPixmap **bmap)
>  {
>    GdkPixmap *p, *b;
>    GdkPixbuf *pixbuf;
>  
>    pixbuf = gdk_pixbuf_new_from_file (filename);
>  
>    p = gdk_pixmap_new (NULL, 20, 20, 8);
>    b = gdk_pixmap_new (NULL, 20, 20, 1);

The first one is incorrect, because you are assuming that the GdkRGB
visual is 8 bits deep, and this may not be the case.  Use the depth of
the GdkRGB visual instead.  You can do this by using

	GdkVisual *visual;
	GdkPixmap *pixmap;

	visual = gdk_rgb_get_visual ();
	p = gdk_pixmap_new (NULL, 20, 20, visual->depth);

The second one is correct, since the _threshold_alpha() function
expects a bitmap, which is a 1-bit deep pixmap.

I am reviving and updating a document about basic X concepts I wrote
some time ago; it will be presented as a feature article in the GNOME
developers site.  You can look at its current state on CVS as
gnome-docu/devel-articles/x-concepts.  It contains information about
drawables, visuals, colormaps, graphics contexts, and other X stuff.

>    /* Render the pixmap */
>    gdk_pixbuf_render_to_drawable (pixbuf, p,
>      gdk_gc_new (p),
>      0, 0,
>      0, 0,
>      20, 20,
>      GDK_RGB_DITHER_NORMAL,
>      0, 0);

You are leaking the GC here.

  Federico



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