How to save XImage as bitmap?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 02:55:53

问题



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

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.


回答1:


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.

See _get_image_surface() in cairo for example:

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

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.



来源:https://stackoverflow.com/questions/4049877/how-to-save-ximage-as-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!