如何使用 cairo 绘制左上角和右下角的矩形?
How to use cairo to draw rectangle with top left and bottom right cut Corner?
我尝试用cairo画了一个左上右下切角的矩形,类似Qt的logo。
这是我想要的:
这是我得到的:
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <cairo.h>
int main()
{
double height = 500, width = 250;
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 500, 500);
cairo_t *cr = cairo_create (surface);
cairo_move_to(cr,0,0);
cairo_line_to(cr,width,0);
cairo_line_to(cr,width,height - height/4);
cairo_line_to(cr,width - height/4,height);
cairo_line_to(cr,0,height);
cairo_set_line_width (cr, 10.0);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_stroke (cr);
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "hello.png");
cairo_surface_destroy (surface);
return 0;
}
我没有得到我想要的结果,有人可以给点提示吗?无论我使用哪种编程语言。
使用更新后的形状,您只是错过了第一笔画。
剩余的笔画需要相应的右移
double cutoff = height/4.0;
cairo_move_to(cr, 0, cutoff);
cairo_line_to(cr, cutoff, 0);
cairo_line_to(cr, width + cutoff, 0);
cairo_line_to(cr, width + cutoff, height - cutoff);
cairo_line_to(cr, width, height);
cairo_line_to(cr, cutoff, height);
我尝试用cairo画了一个左上右下切角的矩形,类似Qt的logo。
这是我想要的:
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <cairo.h>
int main()
{
double height = 500, width = 250;
cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 500, 500);
cairo_t *cr = cairo_create (surface);
cairo_move_to(cr,0,0);
cairo_line_to(cr,width,0);
cairo_line_to(cr,width,height - height/4);
cairo_line_to(cr,width - height/4,height);
cairo_line_to(cr,0,height);
cairo_set_line_width (cr, 10.0);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
cairo_stroke (cr);
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "hello.png");
cairo_surface_destroy (surface);
return 0;
}
我没有得到我想要的结果,有人可以给点提示吗?无论我使用哪种编程语言。
使用更新后的形状,您只是错过了第一笔画。 剩余的笔画需要相应的右移
double cutoff = height/4.0;
cairo_move_to(cr, 0, cutoff);
cairo_line_to(cr, cutoff, 0);
cairo_line_to(cr, width + cutoff, 0);
cairo_line_to(cr, width + cutoff, height - cutoff);
cairo_line_to(cr, width, height);
cairo_line_to(cr, cutoff, height);