问题
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