如何使用Xlib在窗口上的文件中绘制图像 [英] How to draw an image from file on window with Xlib

查看:463
本文介绍了如何使用Xlib在窗口上的文件中绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

int main()
{
    Display *d = XOpenDisplay(0);
    unsigned int bitmap_width, bitmap_height;
    int x, y;
    Pixmap bitmap;

    if ( d )
    {
        Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 400,
                   400, 0, CopyFromParent, CopyFromParent,CopyFromParent, 0, 0);
        GC gc = XCreateGC ( d, w, 0 , NULL );

        int rc = XReadBitmapFile(d, w,
             "1.bmp",
             &bitmap_width, &bitmap_height,
             &bitmap,
             &x, &y);

        XCopyPlane(d, bitmap, w, gc,0, 0, bitmap_width, bitmap_height,0, 0, 1);
        XMapWindow(d, w);
        XFlush(d);
        sleep(10);
    }
    return 0;
}

但是窗口是透明的.我不明白为什么它不起作用.我在哪里弄错了?

But window is clear. I do not understand why it is not working. Where did I make mistake?

推荐答案

通常,您创建自己的加载器以从所需的任何图像格式中获取像素.

Generally you create your own loader to grab the pixels out of whatever image format you need.

然后,使用XCreateImage制作一个XImage,并使用XPutImage将其放置在使用XCreatePixmap生成的屏幕外像素图上.有了像素图后,可使用XCopyArea将其绘制到窗口中.您必须在任何公开事件中重新复制图像.

Then, you use XCreateImage to make an XImage, which you put, using XPutImage, on an offscreen pixmap you generate with XCreatePixmap. Once you have your pixmap, you paint it to the window with XCopyArea. You must re-copy the image on any expose events.

这篇关于如何使用Xlib在窗口上的文件中绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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