gpt4 book ai didi

Android:如何画圆角线?

转载 作者:行者123 更新时间:2023-11-29 15:39:27 27 4
gpt4 key购买 nike

如何绘制圆角线/圆弧,如下图所示?我需要在 Canvas 上绘制它。

enter image description here

最佳答案

我认为您可以通过绘制三条部分重叠的线来解决此问题:

  • 两 strip Paint.Cap.ROUND的外线
  • 一 strip Paint.Cap.BUTT的内线

假设你的输入数据是

float lineWidth = 20;
float lineRadius = 100;
float cornerRadius = 2;

你走如下,

float width, radius;
// Draw outer lines
paint.setStrokeCap(Paint.Cap.ROUND);
width = cornerRadius * 2;

// Draw inner
radius = lineRadius - lineWidth/2f + cornerRadius;
canvas.draw(...)

// Draw outer
radius = lineRadius + lineWidth/2f - cornerRadius;
canvas.draw(...)

// Draw center
paint.setStrokeCap(Paint.Cap.BUTT);
width = lineWidth - 2f*cornerRadius;
radius = lineRadius;
canvas.draw(...)

您可能需要稍微改变中心线的弧角(每边必须 cornerRadius 更长)但这很容易。

关于Android:如何画圆角线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43483865/

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