[Gtk-sharp-list] Scaling Gdk.Pixbuf in a thread

blue_bob bob_kane at ymail.com
Fri Nov 5 06:18:00 EDT 2010


I'm writing an application that allows users to import picture and do some
basic editing like scaling, cropping or rotating. If the image is large the
processing of course takes a while during which the interface does not
respond. So I want to do the processing in a thread.

Right now I have the event callback function that starts a new thread with
the scaling process. When the scaling is done I call a function in my main
class again to draw the pixbuf onto an Gtk.DrawingArea.

I'm afraid my entire approch is wrong so if anyone can come up with a tip I
would be very grateful.

public class ScaleJob
	Gdk.Pixbuf pixbuf;
	double scale_x, scale_y;
	MainClass obj;
	public ScaleJob(Gdk.Pixbuf buf, double scalex,double scaley,
InsertDateTimeAddin _obj)
		scale_x = scalex;
		scale_y = scaley;
		pixbuf = buf;
		obj = _obj;
	public void Run()
		pixbuf = pixbuf.ScaleSimple((int)(scale_x*(double)pixbuf.Width),

private void EventCallback(object source, System.EventArgs args)
	scale_running = true;
	double sx = spin_scale_x.Value, sy = spin_scale_y.Value;//Scale X, Scale Y
	ScaleJob job = new ScaleJob(pixbuf, sx, sy, this);
	(new Thread(new ThreadStart(job.Run))).Start();
public void ScaleJobCB(Gdk.Pixbuf pix)
	pixm.DrawPixbuf(image.Style.BlackGC, pix,
			0, 0, 0, 0, pix.Width, pix.Height,
			RgbDither.None, 0,0);
	image.QueueDrawArea(0,0,600,400);//Image is the Gtk.DrawingArea
	scale_running = false;
View this message in context: http://mono.1490590.n4.nabble.com/Scaling-Gdk-Pixbuf-in-a-thread-tp3028429p3028429.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.

More information about the Gtk-sharp-list mailing list