JavaFX:如何在GraphicsContext上绘制路径? [英] JavaFX: How can a Path be painted on a GraphicsContext?

查看:1259
本文介绍了JavaFX:如何在GraphicsContext上绘制路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaFX在 GraphicsContext 和高级 路径 节点。

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 like GraphicsContext.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?

推荐答案


我是否需要手动迭代Path元素并将它们转换为低级GraphicsContext方法?

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

是的。您需要编写一个翻译器来获取从 Path 并调用相应的图形上下文方法(参见路径渲染方法),例如 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 。将SVGPath从场景图节点数据转换为GraphicsContext方法很容易 - 您只需执行 gc.appendSVGPath(svgPath.getContent())

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上绘制路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆