How to draw an image from file on window with Xlib

*爱你&永不变心* 提交于 2019-12-08 07:59:45

问题


This is my code:

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?


回答1:


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

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.



来源:https://stackoverflow.com/questions/6609281/how-to-draw-an-image-from-file-on-window-with-xlib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!