将 xlib XImage 保存为 PNG

发布于 2024-10-07 16:16:26 字数 157 浏览 0 评论 0原文

我正在使用xlib。

我有一个 XImage 结构,其中填充了来自 XGetImage() 调用的信息。有没有一种流行的方法可以从 XImage 获取更有意义的东西..即 PNG?

我看过 libpng,但几乎每个人都听说它是一头难以驯服的野兽。这仍然是推荐的路径吗?

I am using xlib.

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?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

农村范ル 2024-10-14 16:16:26

另请参阅如何将 XImage 保存为位图?,尽管该人有他们不能使用图书馆的限制。

如果您可以使用图书馆,我相信开罗是一个很好的图书馆,可以为您做到这一点。它具有 PNG 保存功能,可帮助您处理 libpng 的混乱情况,并且具有从 X 获取像素的代码。但是,它可能会使从 XImage 获取像素变得困难;它会想从窗口或像素图中获取它们。如果您可以将 XGetImage() 替换为 cairo,那么它可能会正常工作。我认为在开罗大致做事的方式是:

您还可以使用 Xlib 表面作为源来绘制到图像表面,然后对图像表面执行其他操作(缩放或在其上绘画或其他)如果你愿意的话,然后保存为PNG。

如果您使用任何类型的 UI 工具包,它可能也有相关代码,例如 GTK+ 有 gdk_pixbuf_get_from_drawable() 等。

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

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:

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文