re: Problem with GdkPixbuf



>Hi all:
>    I'm using the Gtkimage and GdkPixbuf to show picture and each time I run the program I get the following error:
>
>GLib-Gobject-CRITICAL ** : g_object_unref : assertion `G_IS_OBJECT(object)` failed
>
>I'm running GTK 2.6.4 and Glib 2.6.4 on a Debian woody.Here is the code which reproduces the problem:
>
>#include
>
> int main( int argc,
>   char *argv[] )
> {
>   GtkWidget *window;
>   GtkWidget *image;
>   GdkPixbuf *pix1;
  GdkPixbuf *pix2;
  
>   gtk_init(&argc, &argv);
>
>   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>   image = gtk_image_new_from_file ("1.png");
>
>   gtk_container_set_border_width (GTK_CONTAINER (window), 10);
>   gtk_container_add (GTK_CONTAINER (window), image);
>
>   pix1=gtk_image_get_pixbuf(GTK_IMAGE(image));
  pix2=gdk_pixbuf_scale_simple(pix1,320,160,GDK_INTERP_BILINEAR);
  gtk_image_set_from_pixbuf(GTK_IMAGE(image),pix2);
  g_object_unref(pix1);
  g_object_unref(pix2); 
 
  gtk_widget_show (image);
>   gtk_widget_show (window);
>
>   gtk_main ();
>
>   return(0);
> }
>
 
>I have no idea how to resolve the problem.Any help will be most appreciated.Thanks.
 
 
 

Hi,

The code load a file, set it on the image control, the get its pixbuf from image, create a second rescaled pixbuf, then set it on image.

I suggest you create the pixbuf from file at desired scale, set it on image and unref :

#include <gtk/gtk.h>

int main (int argc, char **argv)
{

  GtkWidget *window;
  GtkWidget *image;
  GdkPixbuf *pix1;

  gtk_init(&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);

  pix1 = gdk_pixbuf_new_from_file_at_scale ("1.png",320,160, FALSE, NULL);
  image =gtk_image_new_from_pixbuf (pix1);
  gtk_container_add (GTK_CONTAINER (window), image);
  g_object_unref(pix1);
 
  gtk_widget_show_all (window);
 
  gtk_main();
  return(0);
}

Same result, no errors, less code, less memory.

Regards,

Katsankat


百 万 玩 家 同 玩 的 乐 园,人 气 爆 发 的 梦 幻 西 游 >
> [ (pas de nom de fichier) (0.1 Ko) ]



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