[Gtk-sharp-list] Re: System.Drawing.Image <-> Gdk.Pixbuf

Eric Butler eric@extremeboredom.net
Thu May 12 04:34:38 EDT 2005


Give this a shot:

using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

public class ImageTest
	public static void Main()
		Bitmap bitmap = new Bitmap("Cheese.jpg");
		Gtk.Window window = new Gtk.Window("ImageTest");
		Gtk.Image image = new Gtk.Image(ImageToPixbuf(bitmap));

	private static Gdk.Pixbuf ImageToPixbuf(Image image)
		using (MemoryStream stream = new MemoryStream()) {
			image.Save(stream, ImageFormat.Bmp);
			stream.Position = 0;
			Gdk.Pixbuf pixbuf = new Gdk.Pixbuf(stream);
			return pixbuf;


Phil Durand wrote:
> I'm using a third party library which uses System.Drawing.Image and
> whatnot to deal with pictures. I need to convert those images into
> Gdk.Pixbufs to be displayed using GTK#, and vice versa. Is there anyone
> who could point me in the right direction? Someone said something about
> gtk.dotnet but I dont see anything in there that would help me so far.
> Any help would be appreciated,
> Philippe Durand
> Galaxium Messenger
> http://galaxium.sourceforge.net/

More information about the Gtk-sharp-list mailing list