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/

相关文章:

Ubuntu Gnome 3.14 GTK+ 主题位置

haskell - 在 Windows 上安装 Haskell cairo

linker - 使用 mingw 为 x86_64-w64 交叉编译 cairo

c - 将GTK2 +与OpenGL一起使用时出现编译错误?

c - 保存 gtk 窗口位置

python - 如果我在之后立即关闭应用程序,Gtk 不会将文本保存到剪贴板

c++ - 如何使用 Cairo 将 C++ 绘制到使用 GDI 的窗口(而不是创建图像)?

graphics - 在雅典教程中 Canvas 来自哪里?

python-3.x - python pyinstaller 未找到名为 "cairo"的库

c - GtkScrolledWindow + WebkitWebView 滚动