如何在 Java 中绘制 Bézier 路径的控制点?
我创建了一条贝塞尔曲线路径,绘制路径效果很好。但我不知道如何将控制点与路径一起绘制。这是可能的还是我必须在另一个数据结构中跟踪它们?
更新:我想绘制控制点的原因是,我将让用户使用控制点上的手柄来编辑曲线。
我正在使用以下命令创建路径:
Path2D.Double path = new Path2D.Double();
path.moveTo(0,0);
path.curveTo(5, 6, 23, 12, 45, 54);
path.curveTo(34, 23, 12, 34, 2, 3);
并使用以下命令绘制它:
g2.draw(path);
我已经按照 trashgod 的建议使用 PathIterator 进行了测试,但是如果我想要这样管理曲线将很难用户能够编辑控制点。
I have created a Path of Bézier curves and it works fine to draw the path. But I don't know How I can draw the Control Points together with the Path. Is that possible or do I have to keep track of them in another datastructure?
Update: The reason to why I want to draw the control points, is that I will let the user to edit the curves using handles on the control points.
I am creating the path with:
Path2D.Double path = new Path2D.Double();
path.moveTo(0,0);
path.curveTo(5, 6, 23, 12, 45, 54);
path.curveTo(34, 23, 12, 34, 2, 3);
And drawing it with:
g2.draw(path);
I have tested with PathIterator as trashgod suggested, but it will be hard to manage the curves that way if I want the user to be able to edit the control points.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以获得
PathIterator
来引用
Shape
中每个点的坐标数组。编辑时,您可以使用它们沿曲线绘制调整大小手柄和控制点。以下是使用自定义曲线实现进行编辑的示例。You can obtain a
PathIterator
to reference the array of coordinates for each point in theShape
. You can use these to draw resize handles and control points along the curve when editing. Here's an example of editing using a custom curve implementation.