4

だから私はカイロでマスクをセットアップしようとしていますが、違いを生むことはできません. 以下に、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

1 に答える 1

5

わかりました。cairo_mask() が cairo_clip() のように動作することを期待していました。(cairo_clip() では、後で描画されるすべての要素をクリップするクリップ パスを確立します)

cairo_mask は非常に簡単に説明されています。それはまさにそれが行うことです - 画面全体を現在の塗りつぶしパターンで塗りつぶし、マスク上のそのピクセルのアルファが何であれブレンドします。

于 2010-06-22T20:21:24.243 に答える