【问题标题】:How can I draw image with rounded corners in Cairo/Gtk?如何在 Cairo/Gtk 中绘制带圆角的图像?
【发布时间】:2010-11-20 17:09:57
【问题描述】:

如何在 Cairo/Gtk 中绘制带圆角的图像?任何语言。

【问题讨论】:

    标签: gtk cairo


    【解决方案1】:

    好的,很简单。这是vala代码:

    private void draw_rounded_path(Context ctx, double x, double y,
        double width, double height, double radius) {
    
        double degrees = M_PI / 180.0;
    
        ctx.new_sub_path();
        ctx.arc(x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
        ctx.arc(x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
        ctx.arc(x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
        ctx.arc(x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
        ctx.close_path();
    }
    

    expose_event 的例子:

    public override bool expose_event(Gdk.EventExpose event) {
        //base.expose_event(event);
        Context ctx = Gdk.cairo_create(this.window);
    
        draw_rounded_path(ctx, allocation.x, allocation.y, allocation.width,
            allocation.height, 5);
    
        if(pixbuf != null) {
            Gdk.cairo_set_source_pixbuf(ctx, pixbuf, allocation.x, allocation.y);
            ctx.clip();
        }
    
        ctx.paint();
        return false;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 2012-06-04
      • 2014-04-21
      • 2020-04-28
      • 1970-01-01
      • 2012-10-23
      相关资源
      最近更新 更多