gpt4 book ai didi

java - 安卓填充局部圆弧

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:01 30 4
gpt4 key购买 nike

如何使用 paint 和 canvas 方法填充如下所示的两条弧线之间的绿色部分?

这是我画两条弧线的方法,我也可以弄清楚如何用线连接它们,但我不知道如何填充内部区域。

    // set to stroke black
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth((float) STROKE_WIDTH);

// outside arc
RectF arc_oval_outside = new RectF((float) (getX()), (float) (getY()),
(float) (getX() + getWidth()), (float) (getY() + getHeight()));
canvas.drawArc(arc_oval_outside, (float) (0.0), (45.0) (ARC_SWEEP), false, paint);

// inside arc
RectF arc_oval_inside = new RectF((float) (getX() + ARC_WIDTH), (float) (getY() + ARC_WIDTH),
(float) (getX() + getWidth() - ARC_WIDTH), (float) (getY() + getHeight() - ARC_WIDTH));
canvas.drawArc(arc_oval_inside, (float) (0.0), (float) (ARC_SWEEP), false, paint);

最佳答案

下面是绘制带边框的实心圆弧的简单方法:

Point center = new Point(canvas.getWidth()/2, canvas.getHeight()/2);
int inner_radius = 100;
int outer_radius = 150;
int arc_sweep = 90;
int arc_ofset = 30;

RectF outer_rect = new RectF(center.x-outer_radius, center.y-outer_radius, center.x+outer_radius, center.y+outer_radius);
RectF inner_rect = new RectF(center.x-inner_radius, center.y-inner_radius, center.x+inner_radius, center.y+inner_radius);

Path path = new Path();
path.arcTo(outer_rect, arc_ofset, arc_sweep);
path.arcTo(inner_rect, arc_ofset + arc_sweep, -arc_sweep);
path.close();

Paint fill = new Paint();
fill.setColor(Color.GREEN);
canvas.drawPath(path, fill);

Paint border = new Paint();
border.setStyle(Paint.Style.STROKE);
border.setStrokeWidth(2);
canvas.drawPath(path, border);

drawing result

(PathPaint 分配显然不是最优的)

关于java - 安卓填充局部圆弧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17623947/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com