See Also: Pixbuf Members
The Gdk.Pixbuf class is used to represent an image in memory, typically on the client side (this is different from Gdk.Pixmap that represents a server-side image). The in-memory representation uses either a three byte RGB representation or a four byte RGBA representation.
Pixbufs can be created from a number of sources: image files in an assorted set of file formats (png, tiff, jpg, gif, xpm, pcx, ico, xpm, xbm); Drawables (which can be windows on the X server, or off-screen images in the X server) or in-memory images.
A pixbuf can be rendered, scaled or composited into another pixbuf, into a window on the X server, or on a drawable in the X server. Various rendering methods are provided for this purpose.
Pixbufs can also be saved to a number of different file formats.
An example that composites two images next to each other.
C# Example
// Compile with: mcs -pkg:gtk-sharp PixmapComposite.cs // Usage: PixmapComposite.exe image-1.jpg image-2.jpg composite.jpg using Gdk; using System; public class PixmapComposite { public static void Main (string [] args) { // Check arguments, this takes three. if (args.Length < 3) throw new Exception ("USAGE: image1Filename image2Filename " + "compositeFilename"); // Figure out the output type string type = "jpeg"; if (args [2].ToLower ().EndsWith (".jpg")) type = "jpeg"; else if (args [2].ToLower ().EndsWith (".png")) type = "png"; else throw new Exception ("Only JPG and PNG images are supported for " + "the composite image"); // Init the system Gdk.Global.InitCheck(ref args); // Load the images Pixbuf image1 = new Pixbuf (args [0]); Pixbuf image2 = new Pixbuf (args [1]); // Create the composite image Colorspace colorspace = image1.Colorspace; bool hasAlpha = image1.HasAlpha; int bitsPerSample = image1.BitsPerSample; Pixbuf composite = new Pixbuf (colorspace, hasAlpha, bitsPerSample, image1.Width + image2.Width, image1.Height); // Composite the images on the central one image1.Composite (composite, 0, 0, image1.Width, image1.Height, 0.0, 0.0, 1.0, 1.0, InterpType.Hyper, 255); image2.Composite (composite, image1.Width, 0, image2.Width, image2.Height, image1.Width, 0.0, 1.0, 1.0, InterpType.Hyper, 255); // Write out the image as a JPG composite.Save (args [2], type); } }