如何将XImage保存为位图? [英] How to save XImage as bitmap?

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

问题描述



我试图创建JNI C ++库来捕获桌面视频(帧)。
第一步是简单地做一个桌面的屏幕截图。代码是:


i'm trying to create JNI C++ library that will capture desktop video (frames). First step is to simply make a screenshot of desktop. Code is :

#include <iostream>
#include <X11/Xlib.h>

using namespace std;

int main()
{
        Display *display;
        int screen;
        Window root;
        display = XOpenDisplay(0);
        screen = DefaultScreen(display);
        root = RootWindow(display, screen);
        XImage *img = XGetImage(display,root,0,0,400,400,XAllPlanes(),ZPixmap);

        if (img != NULL)
        {
           //save image here
        }
        return 0;
}

但是,如何将img保存为位图文件?
因为目标库是JNI - 它不能使用第三方库。 (据我所知)。

请帮忙。

谢谢。

But, how to save img as bitmap file ? Because target library is JNI - it must not use third-party libraries. (as i understood).
Please, help.
Thank you.

推荐答案

为此,您必须为所有可能的XImage

To do this you have to write a convert routine for all possible XImage formats, or at least all formats your users are likely to have.

在cairo中查看_get_image_surface()例如:

See _get_image_surface() in cairo for example:

  • http://cgit.freedesktop.org/cairo/tree/src/cairo-xlib-surface.c#n727

如果你不能使用第三方库,你必须重新实现类似的东西。
注意,它链接到libpixman的某些格式,所以代码甚至比它看起来更复杂。

If you can't use a third-party library you will have to reimplement something like that. Note that it's chaining to libpixman for some formats so the code is even more complex than it appears there.

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

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