问题描述
JavaFX在和高级节点。
JavaFX provides both low-level path painting methods on a GraphicsContext
and a high-level Path
node.
我想在类中存储形状并在 GraphicsContext
中绘制它们。 Path
类对我来说似乎很方便。我知道,它应该用作场景图中的一个节点,但它包含我需要的所有绘图元素。
I want to store shapes in classes and draw them in a GraphicsContext
. The Path
class seems convenient for me. I know, it is meant to be used as a node in the scene graph, but it contains all drawing elements I need.
我正在寻找像$ b这样的方法$ b GraphicsContext.fillPath(路径)
但没有。
I am looking for a method likeGraphicsContext.fillPath(Path)
but there is none.
我是否需要迭代手动覆盖 Path
元素并将它们转换为低级 GraphicsContext
方法,还是我错过了什么?
Do I have to iterate over the Path
elements by hand and translate them into low-level GraphicsContext
methods, or did I miss something?
推荐答案
是的。您需要编写一个翻译器来获取从并调用相应的图形上下文方法(参见),例如 beginPath()
, moveTo()
, lineTo()
, closePath()
, fill
, stroke()
等。
Yes. You will need to write a translator to take data extracted from a Path
and invoke appropriate graphics context methods (see the Path Rendering methods), for example beginPath()
, moveTo()
, lineTo()
, closePath()
, fill
, stroke()
, etc.
您可以使用。将SVGPath从场景图节点数据转换为GraphicsContext方法很容易 - 您只需执行。
Rather than using a Path, you could perhaps use an SVGPath
. It is easy to translate an SVGPath from a Scene graph node data to a GraphicsContext method - you can just do gc.appendSVGPath(svgPath.getContent())
.
这篇关于JavaFX:如何在GraphicsContext上绘制路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!