hi,

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.

[code]
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),
                                                
(int)(scale_y*(double)pixbuf.Height),InterpType.Nearest);
                obj.ScaleJobCB(pixbuf);
        }
}

private void EventCallback(object source, System.EventArgs args)
{
        if(scale_running)
                return;
        scale_running = true;
        double sx = spin_scale_x.Value, sy = spin_scale_y.Value;//Scale X, 
Scale Y
values
        ScaleJob job = new ScaleJob(pixbuf, sx, sy, this);
        (new Thread(new ThreadStart(job.Run))).Start();
}
                
public void ScaleJobCB(Gdk.Pixbuf pix)
{
        Gdk.Threads.Enter();
        pixm.DrawPixbuf(image.Style.BlackGC, pix,
                        0, 0, 0, 0, pix.Width, pix.Height,
                        RgbDither.None, 0,0);
        Gdk.Threads.Leave();
        image.QueueDrawArea(0,0,600,400);//Image is the Gtk.DrawingArea
        scale_running = false;
}
[/code]         
-- 
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.
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Reply via email to