使用xlib将图像加载到窗口上 [英] Load image onto a window using xlib

查看:178
本文介绍了使用xlib将图像加载到窗口上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

推荐答案

使用

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

为Pixmap创建图形上下文

Create a Graphics Context for the Pixmap

GC XCreateGC(display, d, valuemask, values)

将XImage绘制到Pixmap

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

最后将Pixmap设置为窗口的背景

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.

这篇关于使用xlib将图像加载到窗口上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆