为什么绘制路径不起作用?

发布于 2024-11-29 06:34:21 字数 573 浏览 2 评论 0原文

我有这个绘制路径的代码,但没有显示任何内容,我不明白为什么。

//i move the path's starting point somewhere up here to a point.
//get center x and y are the centers of a picture. it works when i
//do drawline and store the different starting points 
//but i want it to look continuous not like a lot of different
//lines

path.lineTo(a.getCenterX(), a.getCenterY());
path.moveTo(a.getCenterX(), a.getCenterY());


p.setStrokeWidth(50);
p.setColor(Color.BLACK);
canvas.drawPath(path,p);

drawpath image

提前致谢

I have this code for drawpath and nothing shows up and I cant figure out why.

//i move the path's starting point somewhere up here to a point.
//get center x and y are the centers of a picture. it works when i
//do drawline and store the different starting points 
//but i want it to look continuous not like a lot of different
//lines

path.lineTo(a.getCenterX(), a.getCenterY());
path.moveTo(a.getCenterX(), a.getCenterY());


p.setStrokeWidth(50);
p.setColor(Color.BLACK);
canvas.drawPath(path,p);

drawpath image

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雪若未夕 2024-12-06 06:34:21

新的 Paint 实例仅填充路径。

描边路径,请设置绘画样式:

paint.setStyle(Paint.Style.STROKE);

如果您要绘画的背景是黑色,请更改颜色,以便您可以看到绘画:

paint.setColor(Color.RED);   // something other than the background color

可选:

paint.setStrokeWidth(10);  // makes the line thicker

A new Paint instance only fills paths.

To stroke paths, set the Paint style:

paint.setStyle(Paint.Style.STROKE);

If the background you're painting on is black, change the color, so you can see the paint:

paint.setColor(Color.RED);   // something other than the background color

Optional:

paint.setStrokeWidth(10);  // makes the line thicker
微凉徒眸意 2024-12-06 06:34:21

 我必须将其添加到绘画中才能使其发挥作用。不知道为什么。

mPaint.setDither(true);
mPaint.setColor(0xFFFFFF00);
mPaint.setStyle(Paint.Style.STROKE);    
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(3);

  i had to add this to paint in order to make it work. dunno why.

mPaint.setDither(true);
mPaint.setColor(0xFFFFFF00);
mPaint.setStyle(Paint.Style.STROKE);    
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(3);
余生共白头 2024-12-06 06:34:21

我认为解决您的问题的最佳方法是按如下方式更改代码:

private final int strokeWidth = 50;

path.lineTo(a.getCenterX() + strokewidth / 2, a.getCenterY() + strokeWidth / 2);
path.moveTo(a.getCenterX(), a.getCenterY());

p.setStrokeWidth(strokeWidth);
p.setColor(Color.BLACK);
canvas.drawPath(path,p);

您可能必须使用它,但这应该基本上与线条重叠,因此看起来它们是连续的。

您可能需要在绘制方向上放置一个 switch 语句,但这应该是相当简单的。

我希望这有帮助!

I think the best way to solve your problem is by changing the code as follows:

private final int strokeWidth = 50;

path.lineTo(a.getCenterX() + strokewidth / 2, a.getCenterY() + strokeWidth / 2);
path.moveTo(a.getCenterX(), a.getCenterY());

p.setStrokeWidth(strokeWidth);
p.setColor(Color.BLACK);
canvas.drawPath(path,p);

You may have to play with this, but this should basically overlap the lines so it looks like they are continuous.

You will likely have to put a switch statement in for which direction you are drawing in, but that should be fairly trivial.

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文