Gdk.PixbufLoader Class

PixbufLoader is a 'passive' pixbuf loader. It's not actively read pix buf data, but 'listen' for incoming data instead. It's useful in a case where you want to read the image data in small chunks. Typical use of PixbufLoader is when you want to read a very large image data or reading image from a slow media (such as a slow network connection).

You can see the "Images" section of GtkDemo to learn how to use PixbufLoader.

See Also: PixbufLoader Members


public class PixbufLoader : GLib.Object


C# Example

using System;
using System.IO;
using Gtk;
using Gdk;
namespace GtkDemo
        public class PixbufLoaderSample : Gtk.Window
                static Gdk.PixbufLoader pixbufLoader;
                private uint timeout_id;
                private static Gtk.Image progressiveImage;
                private VBox vbox;
                BinaryReader imageStream;
                static void Main ()
                        Application.Init ();
                        new PixbufLoaderSample ();
                        Application.Run ();
                public PixbufLoaderSample () : base ("images")
                        this.DeleteEvent += new DeleteEventHandler (WindowDelete);
                        this.BorderWidth = 8;
                        vbox = new VBox (false, 8);
                        vbox.BorderWidth = 8;
                        this.Add (vbox);
                        Label label = new Gtk.Label ("Progressive image loading");
                        label.UseMarkup = true;
                        vbox.PackStart (label);
                        Gtk.Frame frame = new Gtk.Frame ();
                        frame.ShadowType = ShadowType.In;
                        Alignment alignment = new Alignment (0.5f, 0.5f, 0f, 0f);
                        alignment.Add (frame);
                        vbox.PackStart (alignment, false, false, 0);
                        // Create an empty image for now; the progressive loader
                        // will create the pixbuf and fill it in.
                        progressiveImage = new Gtk.Image ();
                        frame.Add (progressiveImage);
                        StartProgressiveLoading ();
                        this.ShowAll ();
                private void WindowDelete (object o, DeleteEventArgs args)
                        this.Hide ();
                        this.Destroy ();
                        args.RetVal = true;
                private void StartProgressiveLoading ()
                /* This is obviously totally contrived (we slow down loading
                 * on purpose to show how incremental loading works).
                 * The real purpose of incremental loading is the case where
                 * you are reading data from a slow source such as the network.
                 * The timeout simply simulates a slow data source by inserting
                 * pauses in the reading process.
                        timeout_id = GLib.Timeout.Add (150, new GLib.TimeoutHandler (ProgressiveTimeout));
                private  bool ProgressiveTimeout ()
                        if (imageStream == null) {
                                // note you need to provide your own image
                                // at that location to run this sample
                                imageStream = new BinaryReader (new StreamReader ("images/alphatest.png").BaseStream);
                                pixbufLoader = new Gdk.PixbufLoader ();
                                pixbufLoader.AreaPrepared += new EventHandler (ProgressivePreparedCallback);
                                pixbufLoader.AreaUpdated += new AreaUpdatedHandler (ProgressiveUpdatedCallback);
                        if (imageStream.PeekChar () != -1) {
                                byte[] bytes = imageStream.ReadBytes (256);
                                pixbufLoader.Write (bytes, (uint) bytes.Length);
                                return true; // leave the timeout active
                        else {
                                imageStream.Close ();
                                return false; // removes the timeout
                static void ProgressivePreparedCallback (object obj, EventArgs args)
                        Gdk.Pixbuf pixbuf = pixbufLoader.Pixbuf;
                        pixbuf.Fill (0xaaaaaaff);
                        progressiveImage.FromPixbuf = pixbuf;
                static void ProgressiveUpdatedCallback (object obj, AreaUpdatedArgs args)
                        progressiveImage.QueueDraw ();


Namespace: Gdk
Assembly: gdk-sharp (in gdk-sharp.dll)
Assembly Versions: