JavaFX: How can a Path be painted on a GraphicsContext?

為{幸葍}努か 提交于 2019-12-01 08:40:47

问题


JavaFX provides both low-level path painting methods on a GraphicsContext and a high-level Path node.

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.

I am looking for a method like GraphicsContext.fillPath(Path) but there is none.

Do I have to iterate over the Path elements by hand and translate them into low-level GraphicsContext methods, or did I miss something?


回答1:


Do I have to iterate over the Path elements by hand and translate them into low-level GraphicsContext methods?

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.


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()).



来源:https://stackoverflow.com/questions/28043935/javafx-how-can-a-path-be-painted-on-a-graphicscontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!