c++ - 如何将XImage保存为位图?

标签 c++ linux java-native-interface x11 xlib


我正在尝试创建 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/

相关文章:

java - Java类可以实现C++接口(interface)吗

python - Ctypes 抛出 "WindowsError: [Error 193] %1 is not a valid Win32 application",但这不是 32/64 位问题

c++ - 计算 GLSL 的逐顶点切线

Python 脚本打开并写入终端

Cygwin html 到浏览器

android - 音频记录 : How can I use a common buffer to use it for processing and storing?

android - 在android中使用opencv将检测到的人脸与现有人脸数组进行比较

c++ - 构建 Qt 应用程序时如何运行 git 命令

linux - 适用于 Linux 的可移植 gcc

java - 使用 jni 时在 std::_List_const_iterator<Exiv2::Exifdatum>::operator++ 中获取 SIGSEGV