开发者

Load image onto a window using xlib

I've created window class and i want to insert an image as a background of that window. File formats need to be png. I used XImage of magick++ to load an image. but don't know how to make its as a background of my window. Any idea how to do 开发者_开发技巧it?


Create an Pixmap using

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

Create a Graphics Context for the Pixmap

GC XCreateGC(display, d, valuemask, values)

Draw the XImage to the Pixmap

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

Finally set the Pixmap as the window's background

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

Then free all resources no longer needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜