Save current window as image using gtk #

How to save the current window as an image file, for example png?

I know that I can get gdkWindow from current windows. I can even get an image. From this image structure, I can even request every pixel. But from what I understand, I really need to get pixbuf.

int width; int height; this.GetSize(width, height); this.GdkWindow.GetImage(0,0,width,height).? 

How to get pixbuf from gtk window or gdk window or gdk image?

EDIT

 int width; int height; this.GetSize(out width, out height); Pixbuf pixbuf = Pixbuf.FromDrawable (this.GdkWindow, this.Colormap, 0, 0, 0, 0, width, height); pixbuf.Save("/tmp/out.png","png"); 

works. Png is exported with the correct size, but blurred.

EDIT 2

The solution works. Blur was a mistake viewing images of gnomes

+1
source share
1 answer

Use gdk_pixbuf_get_from_drawable to get from GdkWindow to GdkPixbuf , and then if you want to save to a file, use gdk_pixbuf_save .

In Cairo, which is a more reliable method, you can use cairo_image_surface_create , pass the result to cairo_create , go to gdk_cairo_set_source_window , copy the image with cairo_paint to your surface and write your image with cairo_surface_write_to_png .

Also note that your question is similar to this one . However, since the answer to this question does not work, if my answer answers your question, I will close another question as a deception of this.

0
source

Source: https://habr.com/ru/post/897850/


All Articles