2010-06-22 38 views
3

所以我试图在开罗设置一个面具,但不能让它有任何区别。下面我有一个简单的程序基于这里的一个: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; 
} 

回答

4

好的我想通了。我期待cairo_mask()的行为像cairo_clip()。 (在cairo_clip()中,它创建了一个剪辑路径,用于剪辑之后绘制的每个元素)

cairo_mask的解释非常简单:“cairo_mask - 使用alpha通道蒙版模式绘制当前源填充图案。这正是它所做的 - 用当前的填充图案填充整个屏幕,并将其与面罩上该像素的任何alpha混合。

+0

我知道很多时间过去了,但cairo_mask与xps中的opacityMask相同吗? – Michele 2015-03-19 19:15:32

相关问题