gpt4 book ai didi

android - 我如何根据笔划帽计算从哪里开始我的线?

转载 作者:行者123 更新时间:2023-11-29 20:51:56 25 4
gpt4 key购买 nike

我正在尝试画一条线,但我需要考虑笔划帽的宽度,以免溢出容器。

我有这样的代码......

private void initialize() {
this.paint = new Paint();
this.paint.setColor(Color.BLACK);
this.paint.setStyle(Paint.Style.STROKE);
this.paint.setStrokeCap(Paint.Cap.ROUND);
this.paint.setStrokeWidth(1);
}

public void setStrokeWidth(float strokeWidth) {
this.paint.setStrokeWidth(strokeWidth);
}

public void onDraw(Canvas canvas) {
int x_start, x_end, y, cap_width;
y = this.getHeight() / 2;
x_start = cap_width; //Need to compensate for cap.
x_end = this.getWidth() - cap_width; //Need to compensate for cap.

canvas.drawLine(x_start, y, x_end, y, paint);
}

注意在上面代码的onDraw方法中,我需要计算帽的宽度。我该如何计算?

最佳答案

在写问题时,我意识到答案对某些人来说可能相当明显。对于那些没有清晰思考的人(我没有),这里是解决方案。

笔帽的半径始终是笔划宽度的一半。

cap_width = (int)paint.getStrokeWidth / 2;

关于android - 我如何根据笔划帽计算从哪里开始我的线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28909206/

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