GtkSharp/gdk/Pixbuf.custom

65 lines
2.3 KiB
Text
Raw Normal View History

IntPtr LoadFromStream (System.IO.Stream input)
{
PixbufLoader loader = new PixbufLoader ();
byte [] buffer = new byte [8192];
int n;
while ((n = input.Read (buffer, 0, 8192)) != 0)
loader.Write (buffer, (uint) n);
loader.Close ();
return loader.Pixbuf.Handle;
}
public Pixbuf (System.IO.Stream input)
{
Raw = LoadFromStream (input);
}
public Pixbuf (System.Reflection.Assembly assembly, string resource)
{
if (assembly == null)
assembly = System.Reflection.Assembly.GetCallingAssembly ();
System.IO.Stream s;
Pixbuf p = null;
using (s = assembly.GetManifestResourceStream (resource))
Raw = LoadFromStream (s);
}
// scale_simple, composite_color_simple, and addalpha do a gdk_pixbuf_new on the
// return first, and we also ref it
// in the GetObject. So get rid of one extra reference.
[DllImport("gdk_pixbuf-2.0")]
static extern IntPtr gdk_pixbuf_scale_simple(IntPtr raw, int dest_width, int dest_height, int interp_type);
public Gdk.Pixbuf ScaleSimple(int dest_width, int dest_height, Gdk.InterpType interp_type) {
IntPtr raw_ret = gdk_pixbuf_scale_simple(Handle, dest_width, dest_height, (int) interp_type);
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret);
ret.Unref ();
return ret;
}
[DllImport("gdk_pixbuf-2.0")]
static extern IntPtr gdk_pixbuf_composite_color_simple(IntPtr raw, int dest_width, int dest_height, int interp_type, int overall_alpha, int check_size, uint color1, uint color2);
public Gdk.Pixbuf CompositeColorSimple(int dest_width, int dest_height, Gdk.InterpType interp_type, int overall_alpha, int check_size, uint color1, uint color2) {
IntPtr raw_ret = gdk_pixbuf_composite_color_simple(Handle, dest_width, dest_height, (int) interp_type, overall_alpha, check_size, color1, color2);
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret);
ret.Unref ();
return ret;
}
[DllImport("gdk_pixbuf-2.0")]
static extern IntPtr gdk_pixbuf_add_alpha(IntPtr raw, bool substitute_color, byte r, byte g, byte b);
public Gdk.Pixbuf AddAlpha(bool substitute_color, byte r, byte g, byte b) {
IntPtr raw_ret = gdk_pixbuf_add_alpha(Handle, substitute_color, r, g, b);
Gdk.Pixbuf ret = (Gdk.Pixbuf) GLib.Object.GetObject(raw_ret);
ret.Unref ();
return ret;
}