Gtk windows support transparency using Cairo. I tried to get a screenshot with the code here . But it prints pure black for windows that use transparency. How can I take a screenshot (PNG), which also calls the alpha channel?
EDIT: I tried with alpha pixbuf, but the output is still no alpha. Here is my code (sing Gtk #, but it is very similar to C):
static void GetScreenshot(Gtk.Window win) { var pixbuf = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 8, 500, 500); var pix = pixbuf.GetFromDrawable(win.GdkWindow, win.Colormap, 0, 0, 0, 0, 500, 500); pix.Save("/home/blez/Desktop/screenshot.png", "png"); }
Here's the conclusion: 
EDIT: I did it with the surface of Cairo. Here is the code I used:
static void GetScreenshot(Gtk.Window win) { var src_context = Gdk.CairoHelper.Create(win.GdkWindow); var src_surface = src_context.Target; var dst_surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, win.Allocation.Width, win.Allocation.Height); var dst_context = new Cairo.Context(dst_surface); dst_context.SetSourceSurface(src_surface, 0, 0); dst_context.Paint(); dst_surface.WriteToPng("screenshot.png"); }
source share