2


我正在尝试创建将捕获桌面视频(帧)的 JNI C++ 库。第一步是简单地制作桌面截图。代码是:

#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 - 它不能使用第三方库。(据我了解)。
请帮忙。
谢谢你。

4

1 回答 1

3

为此,您必须为所有可能的 XImage 格式或至少您的用户可能拥有的所有格式编写一个转换例程。

参见 cairo 中的 _get_image_surface() 例如:

如果你不能使用第三方库,你将不得不重新实现类似的东西。请注意,对于某些格式,它链接到 libpixman,因此代码比那里显示的还要复杂。

于 2010-10-29T14:46:54.437 回答