public static Gdk.Pixbuf CaptureImage(Gdk.Rectangle rectSelection) { Window winRoot = Gdk.Screen.Default.RootWindow; Gdk.Pixbuf pix = new Gdk.Pixbuf(Colorspace.Rgb, true, 8, rectSelection.Width, rectSelection.Height); pix.GetFromDrawable(winRoot, winRoot.Colormap, rectSelection.X, rectSelection.Y, 0, 0, rectSelection.Width, rectSelection.Height); Console.WriteLine("capture: image captured"); return pix; }
public static Gdk.Pixbuf CaptureScreen() { int width = 0; int height = 0; Window winRoot = Gdk.Screen.Default.RootWindow; winRoot.GetSize(out width, out height); Gdk.Pixbuf pix = new Gdk.Pixbuf(Colorspace.Rgb, true, 8, width, height); pix.GetFromDrawable(winRoot, winRoot.Colormap, 0, 0, 0, 0, width, height); Console.WriteLine("capture: screen captured"); return pix; }
static bool MakeShot() { Console.WriteLine(wc.Location); Gdk.Window win = wc.GdkWindow; int iwidth = wc.Allocation.Width; int iheight = wc.Allocation.Height; Gdk.Pixbuf p = new Gdk.Pixbuf (Gdk.Colorspace.Rgb, false, 8, iwidth, iheight); Gdk.Pixbuf scaled; p.GetFromDrawable (win, win.Colormap, 0, 0, 0, 0, iwidth, iheight); if (width == -1){ if (height == -1) scaled = p; else scaled = p.ScaleSimple (height * iwidth / iheight, height, Gdk.InterpType.Hyper); } else { if (height == -1) scaled = p.ScaleSimple (width, width * iheight / iwidth, Gdk.InterpType.Hyper); else scaled = p.ScaleSimple (width, height, Gdk.InterpType.Hyper); } scaled.Save (output, "png"); Application.Quit (); return true; }