使用gtk将当前窗口保存为图像# [英] save current window as image using gtk#

查看:193
本文介绍了使用gtk将当前窗口保存为图像#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将当前窗口保存为像png这样的图像文件?



我知道我可以从当前窗口获取gdkWindow。
我甚至可以得到一张图片。从这个图像结构我甚至可以查询每个像素。但根据我的理解,我真正需要的是获得pixbuf。

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

如何从
a gtk窗口或
a gdk窗口获得pixbuf或
a gdk image?



编辑

  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);

有点不错。一个PNG导出的大小正确但模糊。



编辑2



解决方案正在运行。模糊是gnome图片浏览器的一个bug

解决方案

使用 gdk_pixbuf_get_from_drawable GdkWindow 添加到 GdkPixbuf ,那么如果你想保存到一个文件,使用 gdk_pixbuf_save



在开罗,这是更具前瞻性的方法,您可以使用 cairo_image_surface_create ,将结果传递给 cairo_create ,将它传递给 gdk_cairo_set_source_window ,请使用 cairo_paint复制到您的图片界面 ,然后用 cairo_surface_write_to_png

另外请注意,您的问题类似于这一个。然而,由于这个问题的答案不起作用,如果我的答案回答你的问题,我将把另一个问题作为这个问题的结束。


How can I save the current window as an image file such as a png?

I know I can get a gdkWindow from current windows. I can even get an image. From this image struct I can even query each pixel. But from what I understand what I really need is to get a pixbuf.

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

How do I get a pixbuf from a gtk window or a gdk window or a 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");

is kinda working. A png is exported with the correct size but it is blurred.

EDIT 2

The solution is working. The bluriness was a bug of gnome image viewer

解决方案

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

In Cairo, which is the more future-proof method, you could use cairo_image_surface_create, pass the result to cairo_create, pass that to gdk_cairo_set_source_window, copy to your image surface with cairo_paint, 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 that question does not work, if my answer answers your question, I'll close the other question as a dupe of this.

这篇关于使用gtk将当前窗口保存为图像#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆