Re: Changing Pixbuf attached to a GooCanvasImage



On Wed, 2012-01-04 at 11:09 +0000, Luc A. wrote:
> Hello !
> 
> 
> Just a simple answer. If I build a new goocanvasimage item, with a
> pixbuf named, for example, "pb1", and, in a second time, modify the
> object corresponding to my goocanvasimage, by using of G_object_set()
> on the "pixbuf" field, I've noticed that the image shown changes on
> the screen, it's OK for me.
> 
> 
> short example to explain
> --------------
> GdkPixbuf* pb1, *pb2;
> 
> 
> /* we suppose pb1 & pb2 correctly initialized */
> 
> 
> GooCanvasItem* pDrawings=goo_canvas_image_new(ancestor,pb1, 320, 200 ,
> NULL);
> 
> 
> /* at this moment, the image is hown using the pb1 pixbuf */
> /* then I modifiy the image as follows */
>  g_object_set(G_OBJECT(pDrawings), "pixbuf", pb2,  NULL);/* modifiy
> visible object */
> 
> /* is the pb1 pixbuf is freed ???? */
> ----------------
> 
> 
> But, the concern is : the old pixbuf is freed by goocanvas or remains
> in memory, and, in this case, how to access to the old pixbuf, since
> the "pixbuf" field of the goocanvasimage item is "write only".

The pixbuf is converted to a cairo_pattern_t inside GooCanvasImage.
(This is why the "pixbuf" property is write only. It is never stored.)

If you set the "pixbuf" property again, the old cairo_pattern_t is
unref'ed, and possibly freed.


If you don't need a pixbuf any more (e.g. after setting the "pixbuf"
property), you should call g_object_unref() on it.

Normally you would do something like this:

  GdkPixbuf *im = gdk_pixbuf_new_from_file ("toroid.png", NULL);
  GooCanvasItem *image = goo_canvas_image_new (root, im, ......);
  g_object_unref (im);

Damon




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