[Gtk-sharp-list] How set the Image displayed by Gtk.Image (using a IO.Stream)

Michael Hutchinson m.j.hutchinson at gmail.com
Mon Feb 23 13:49:38 EST 2009

On Sat, Feb 7, 2009 at 2:15 AM, cyanidejunkie <dkomen at gmail.com> wrote:
> Hey guys,
> I am a long time c# .Net coder but new to  monodevelop and gtk#.
> I already have a System.IO.Stream which contains jpg data as streamed from a
> uri (http://www............image.jpg).
> I have a gtk image (image1) on my stetic form and I want it to show the
> image in my sream when I click on some or other button.
> I would have though it would be something like the following pseudo code  :
> image1.Image = Gt.Image.LoadFromStream(myStream);
> How do I actually set an image's 'image' from a mono stream?

A Gtk.Image is a widget that displays a Pixbuf or Pixmap, which are
the underlying image representations in Gdk.

There are a number of convenience constructors to load images directly
into a Gtk.Image, from files, streams, resource names, etc. However,
if you want to modify an existing Image widget, I think you'd have to
assign a pixbuf or pixmap directly.

Something like:

using (Gdk.Pixbuf oldPixbuf = image1.Pixbuf) {
    image1.Pixbuf = new Gdk.Pixbuf (myStream);

(this will dispose of the old Pixbuf, which i think is the 'correct'
thing to do)

Michael Hutchinson

More information about the Gtk-sharp-list mailing list