在 x11 窗口中显示带有 alpha 通道的图像

问题描述 投票:0回答:0

我已经创建了一个带有透明背景的窗口并且可以使它无边框但首先我想显示一个只有 uint32* 的图像。

当我尝试使用 XPutImage 时它说

X 请求失败错误:BadMatch(参数属性无效) 失败请求的主要操作码:72(X_PutImage) 失败请求序号:15

我不知道为什么。

如果有人需要看的话,这是我的代码

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <thread>

int main(int argc, char* argv[])
{
    uint32_t height = 64;
    uint32_t width = 64;

    Display* display = XOpenDisplay(NULL);

    XVisualInfo vinfo;
    XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo);

    XSetWindowAttributes attr;
    attr.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone);
    attr.border_pixel = 0;
    attr.background_pixel = 0;

    Window win = XCreateWindow(display, DefaultRootWindow(display), 0, 0, width, height, 0, vinfo.depth, InputOutput, vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr);
    XSelectInput(display, win, StructureNotifyMask);
    GC gc = XCreateGC(display, win, 0, 0);

    //attr.override_redirect = True;
    //XChangeWindowAttributes(display, win, CWOverrideRedirect, &attr);

    Atom wm_delete_window = XInternAtom(display, "WM_DELETE_WINDOW", 0);
    XSetWMProtocols(display, win, &wm_delete_window, 1);

    XMapWindow(display, win);

    int32_t data[64 * 64];


    XImage *image = XCreateImage(display, DefaultVisual(display, DefaultScreen(display)), 8, ZPixmap, 0, (char *) data, width, height, 32, 0);

    XPutImage(display, win, DefaultGC(display, DefaultScreen(display)), image, 0, 0, 0, 0,width, height);

    XFlush(display);

    int keep_running = 1;
    XEvent event;
    while (keep_running) {
        XNextEvent(display, &event);
        //to-do
    }`

    XDestroyWindow(display, win);
    XCloseDisplay(display);
    return 0;
}
c++ x11
© www.soinside.com 2019 - 2024. All rights reserved.