【问题标题】:Xlib - draw only set bits of a bitmap on a windowXlib - 在窗口上仅绘制位图的设置位
【发布时间】:2012-05-17 19:23:00
【问题描述】:

我正在尝试在窗口上绘制位图。我只需要在位图中绘制1位对应的像素;对应于 0 位的那些应保持不变。我正在使用这样的代码:

XImage *image;
uint8_t bitmap[8192]; /* 256 x 256 / 8 */

memset(bitmap, 0xaa, sizeof(bitmap));

XSetForeground(g_display, g_gc, 0x000000ff);
XSetBackground(g_display, g_gc, 0x00000000);

image = XCreateImage(g_display, g_visual, 1, XYBitmap,
    0, (char *)bitmap, 256, 256, 32, 0);
XPutImage(g_display, g_wnd, g_gc, image, 0, 0, 10, 10, 255, 255);
XFree(image);

(是的,我知道像我这样直接指定颜色是错误的,但我现在可以)。

显然,位图的 0 位是用背景色(即黑色)绘制的。我希望它们根本不被绘制。实现它的最佳方法是什么?有什么方法可以指定掩码之类的吗?

【问题讨论】:

    标签: c linux x11 xlib


    【解决方案1】:

    首先,对于非透明位图,您不需要从位图数据创建全深度图像。创建一位像素图并使用XCopyPlane

    对于透明位图,您需要操作 GC 的剪辑蒙版。

    Pixmap bitmap;
    ...; /* create 1-bit-deep pixmap */
    XSetClipMask(display, gc, bitmap);
    XSetClipOrigin(display, gc, x, y);
    /* 1-bits of the bitmap are filled with the foreground color,
       and 0-bits are left intact */
    XFillRectangle(display, window, gc, x, y, width, heiht);
    

    【讨论】:

    • 来自未来的一些随机感谢 - 我想将 1bpp 图像复制到我的显示器上,并且没有文档规范地指向 XCopyPlane 的方向。我现在有一些0x55(垂直线)进入我的窗口:)
    猜你喜欢
    • 2011-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多