[Gtk-sharp-list] System.Drawing.Image from Gtk.Image

Michael Hutchinson m.j.hutchinson at gmail.com
Fri Dec 23 19:07:18 EST 2005


Hi,

> Is possible i get a System.Drawing.Image and transform to Gtk.Image?
>
> if yes, anyone have a sample? or can tell me how?

Gtk.Image can load Gdk.Pixbufs. Pixbufs can load from common image
encodings. So use the following function to get your pixbuf by saving
the System.Drawing.Image into memory then loading into the pixbuf
(originally posted by Eric Butler in May:
http://lists.ximian.com/pipermail/gtk-sharp-list/2005-May/005880.html)

private Gdk.Pixbuf ImageToPixbuf (System.Drawing.Image image)
{
	using (System.IO.MemoryStream stream = new System.IO.MemoryStream ()) {
		image.Save (stream, System.Drawing.Imaging.ImageFormat.Bmp);
		stream.Position = 0;
		return new Gdk.Pixbuf (stream);
	}
}


Michael


More information about the Gtk-sharp-list mailing list