我正在尝试创建 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 - 它不能使用第三方库。 (据我了解)。
请帮忙。
谢谢。
最佳答案
为此,您必须为所有可能的 XImage 格式或至少您的用户可能拥有的所有格式编写一个转换例程。
请参阅开罗的 _get_image_surface() 示例:
如果您无法使用第三方库,您将不得不重新实现类似的东西。 请注意,对于某些格式,它链接到 libpixman,因此代码比其中显示的更为复杂。
关于c++ - 如何将XImage保存为位图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4049877/