将xlib XImage保存为PNG [英] Saving xlib XImage to PNG

查看:108
本文介绍了将xlib XImage保存为PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xlib.

我有一个XImage结构,其中填充了来自XGetImage()调用的信息.是否有一种流行的方法可以使XImage变得更有意义,例如PNG?

I have an XImage structure filled with information from an XGetImage() call. Is there a popular method to get from XImage to something more meaningful.. namely PNG?

我看过libpng,但是几乎每个人都听说它是驯服的野兽.这仍然是推荐的方法吗?

I have looked at libpng, but have heard from pretty much everyone that it's a beast to tame. Would this still be the recommended path to take?

推荐答案

另请参见如何将XImage另存为位图?,尽管该人受到限制,无法使用库.

See also How to save XImage as bitmap? though that person had the constraint that they couldn't use a library.

如果您可以使用图书馆,那么我相信开罗将是一个很好的图书馆.它为您节省了处理PNG的libpng混乱的PNG,并且具有从X获取像素的代码.它将希望从窗口或像素图中获取它们.如果您可以将XGetImage()替换为cairo,则可能会正常工作.我认为您在开罗大致上会做事的方式是:

If you can use a library, Cairo is a good one that will do this for you I believe. It has PNG saving dealing with the libpng mess for you, and it has code to get the pixels from X. However, it may make it hard to get pixels from an XImage; it will want to get them from a window or pixmap. If you can just replace your XGetImage() with cairo, then it might work fine. The way you would do things roughly in cairo I think is:

在保存为PNG之前,您还可以使用Xlib表面作为源来绘制图像表面,然后根据需要对图像表面进行其他处理(缩放或在其上进行绘画或其他操作).

You could also use the Xlib surface as source to draw to an image surface, and then do other stuff with the image surface (scale or paint on it or whatever) if you wanted, before saving as PNG.

如果您使用的是任何一种UI工具包,它可能也都有相应的代码,例如GTK +具有gdk_pixbuf_get_from_drawable()等.

If you're using any kind of UI toolkit, it probably has code for this too, e.g. GTK+ has gdk_pixbuf_get_from_drawable() etc.

这篇关于将xlib XImage保存为PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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