2007/10/9, Alexander Trauzzi <[EMAIL PROTECTED]>:
> I'm slightly confused. What's the difference between the Gtk and Gdk
> namespace?
>
Taken directly from http://gtk.org/tutorial/c24.html:
"... GTK is built on top of GDK (GIMP Drawing Kit) which is basically
a wrapper around the low-level functions for accessing the underlying
windowing functions (Xlib in the case of the X windows system), and
gdk-pixbuf, a library for client-side image manipulation."
> As well, I want to create an image in memory that then gets displayed in an
> image control, specifically "Gtk.Image"...
To mix two images you can use the Composite method on a Gdk.Pixbuf.
Attach is a sample showing this and how drawing can be made on a
Drawable. It's pretty low level, so using System.Drawing with a
DrawingArea might be easier (and there are many tutorials available on
that topic).
The docs at http://gtk.org/api/ has all the details on Gdk and Gtk.
Eskil
using System;
using Gtk;
// Sample showing the use of Gdk.Pixbuf and Gdk.Pixmap.
public class PixbufSample
{
public static void Main ()
{
Application.Init();
Window w = new Window("Pixbuf Sample");
w.Realize(); // Make sure the GdkWindow is avalable. The depth is used below.
HBox box = new HBox();
w.Add(box);
// 1. Mix two images
Gdk.Pixbuf bg = new Gdk.Pixbuf("bg.jpg");
Gdk.Pixbuf fg = new Gdk.Pixbuf("fg.png");
Gdk.Pixbuf both = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8,
Math.Max(bg.Width, fg.Width), Math.Max(bg.Height, fg.Height));
both.Fill(0);
// Draw the background and foreground onto the new pixbuf. One can also
// just draw onto the bg pixbuf if it's known that the fg pixbuf will fit.
bg.CopyArea(0, 0, bg.Width, bg.Height, both, 0, 0);
fg.Composite(both, 0, 0, fg.Width, fg.Height, 0, 0, 1, 1,
Gdk.InterpType.Bilinear, 255);
Image image = new Image(both);
box.Add(image);
// 2. Do some custom drawing. A Pixmap is an an offscreen drawable.
Gdk.Pixmap pixmap = new Gdk.Pixmap(null, 100, 100, w.GdkWindow.Depth); // Get the depth from the window
using (Gdk.GC gc = new Gdk.GC(pixmap))
{
Gdk.Colormap colormap = Gdk.Colormap.System;
// Create and allocate the colors
Gdk.Color white = new Gdk.Color(255, 255, 255);
colormap.AllocColor(ref white, true, true);
Gdk.Color blue = new Gdk.Color(0, 0, 255);
colormap.AllocColor(ref blue, true, true);
// Draw the background
gc.Foreground = white;
pixmap.DrawRectangle(gc, true, 0, 0, 100, 100);
// Draw a line
gc.Foreground = blue;
pixmap.DrawLine(gc, 0, 0, 100, 100);
}
image = new Image(pixmap, null);
box.Add(image);
w.ShowAll ();
Application.Run ();
}
}
_______________________________________________
Gtk-sharp-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list