开罗遮罩 - 我是否漏掉了什么?

4

所以我正在尝试在Cairo中设置遮罩,但是无法使其产生任何影响。下面我有一个简单的程序,基于这个程序:http://snipplr.com/view/22584/cairo-hello-world-examble/

我设置了一个完全透明的遮罩,所以不应该画出任何东西,但似乎没有任何效果-文本仍然被绘制。我的代码如下。我错过了什么?

谢谢!

int main(int argc, char* argv[])
{                               
    cairo_surface_t* surface;     
    cairo_t* cr;                  

    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 200, 40);
    cr = cairo_create (surface);

    //****
    // Here I create a pattern with an alpha of zero and set it to be cairo's mask
    // According to http://www.cairographics.org/manual/cairo-context.html#cairo-mask
    // "Opaque areas of pattern are painted with the source, transparent areas are not painted."
    // Shouldn't this make it so nothing gets drawn?
    //****

    cairo_pattern_t* nothing = cairo_pattern_create_rgba(0,0,0,0);
    cairo_mask (cr, nothing);

    cairo_text_extents_t te;
    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
    cairo_select_font_face (cr, "Georgia",
                          CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_font_size (cr, 20.0);
    cairo_text_extents (cr, "hello cairo!", &te);
    cairo_move_to (cr, 20, 20);
    cairo_show_text (cr, "hello cairo!");
    cairo_fill(cr);

    // An image gets drawn that says "hello cairo!" in big letters
    cairo_surface_write_to_png(surface, "hello_cairo.png");

    return 0;
}
1个回答

5

好的,我明白了。我原本期望cairo_mask()的行为类似于cairo_clip()。(在cairo_clip()中,它会建立一个剪切路径,将之后绘制的每个元素都进行剪切)

cairo_mask非常简单地解释为:"cairo_mask -- 使用alpha通道遮罩模式绘制当前源填充图案。" 它确实做到了这一点-用当前的填充图案填满整个屏幕,并根据遮罩上该像素的alpha值对其进行混合。


我知道很长时间过去了,但是cairo_mask和xps中的opacityMask是一样的吗? - Michele

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接