【问题标题】:Load image onto a window using xlib使用 xlib 将图像加载到窗口中
【发布时间】:2011-06-17 11:19:44
【问题描述】:

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

【问题讨论】:

    标签: c++ imagemagick x11 xlib


    【解决方案1】:

    使用

    创建像素图
    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 绘制到像素图

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

    最后将像素图设置为窗口的背景

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

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

    【讨论】:

    • 如果 Drawable d 是像素图,xcreategc 的值掩码和值应该是多少?
    • 你能提供一个使用用户数据绘制图像的程序吗?
    猜你喜欢
    • 2019-06-24
    • 2018-11-30
    • 2021-04-20
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    相关资源
    最近更新 更多