gtk - 如何在 Cairo/Gtk 中绘制圆角图像?

标签 gtk cairo

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

最佳答案

好吧,这真的很简单。这是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;
}

关于gtk - 如何在 Cairo/Gtk 中绘制圆角图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4183546/

相关文章:

python-3.x - Cairo 示例适用于 Python 2.7 但不适用于 Python 3

GTK+ 3 的 Ruby 绑定(bind)?

c - 如何使用开罗和 Gtk3 在 GtkDrawingArea 中绘制一条线

尝试检索 GTKEntry 的文本值时出现严重错误

python - 如何编写扩展的 gtk.CellRendererText() 以在文本旁边显示图像

绘图区开罗多个形状

build - 找不到 Pixman - Cmake 错误

python - 如何创建内存中图像

python - 回调函数中的 AttributeError

python - 如何在图像菜单项中使用自定义图标?