使用 xlib 将图像加载到窗口上

2024-04-27

我已经创建了窗口类,我想插入图像作为该窗口的背景。文件格式必须为 png。我使用magick++的XImage来加载图像。但不知道如何将其作为我的窗口的背景。知道怎么做吗?


使用创建像素图

Pixmap XCreatePixmap(display, d, width, height, depth)
      Display *display; // The display
      Drawable d;       // The Window for which to set the background

为像素图创建图形上下文

GC XCreateGC(display, d, valuemask, values)

将 XImage 绘制到 Pixmap

XPutImage(display, pixmap, gc, image, src_x, src_y, dest_x, dest_y, width, height)
        Drawable d; // The Pixmap
        XImage *image; // your XImage

最后将 Pixmap 设置为窗口背景

XSetWindowBackgroundPixmap(display, w, background_pixmap)
      Display *display;
      Window w;
      Pixmap background_pixmap;

然后释放不再需要的所有资源。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 xlib 将图像加载到窗口上 的相关文章

随机推荐