2010-06-22 45 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

相關問題