[Gtk-sharp-list] How can I save a cairo imagesurface as a pixbuf

Christian Hoff christian_hoff at gmx.net
Thu Dec 25 13:09:26 EST 2008


You're right the effect only shows up if you have a large number of 
rows. But not storing the images as a pixbuf leads to a considerable 
performance improvement. I used my EAN13 class in a treeview that had 
about 10.000 rows. In earlier versions it was derived from 
CellRendererPixbuf and the load was awfully slow(about 30 seconds!) 
because Gtk+ renders not just the visible cells, but instead all of them.

That's why I tested the approach to subclass directly from CellRenderer 
and create the image in the render method using Cairo. And suddenly 
everything was 10 times faster(yes it was really that much a 
difference). BTW the CellRendererPixbuf uses cairo as well:

  cr = gdk_cairo_create (window);
 
  gdk_cairo_set_source_pixbuf (cr, pixbuf, pix_rect.x, pix_rect.y);
  gdk_cairo_rectangle (cr, &draw_rect);
  cairo_fill (cr);

  cairo_destroy (cr);

Christian

Andy Selvig wrote:
>>> Using a CellRendererPixbuf and converting all your images into a pixbuf takes much more time.
>>>       
>
> Are you sure? Yes, it would definitely take more time up front, but it
> seems like in general it would be faster to have them stored as
> pixbufs that the renderer could just dump on to the screen. Doesn't
> this method force every single cell to be freshly drawn every time the
> tree view is rendered? Cairo is great, but speed isn't exactly its
> thing.
>
> In the end, it probably doesn't matter much unless you have a
> ridiculous number of cell shown.
>   


More information about the Gtk-sharp-list mailing list