将几何图形转换为 wpf 中的路径(使用混合?)
我的问题很简单。
我怎样才能将此代码转换
<Path>
<Path.Data>
<EllipseGeometry Center="5,4" RadiusX="4" RadiusY="4"/>
</Path.Data>
</Path>
为类似的东西
<Path Data="M 0 5 L 3 10 10 0"/>
(请注意,第二个生成一个复选标记,而不是椭圆形。这只是为了说明目的,我的目标就是:找到什么序列给出了椭圆形)
编辑:我也阅读有关 xaml 中贝塞尔曲线的文档,我完全意识到我可以通过计算贝塞尔曲线的精确点来简单地生成正确的代码以获得椭圆,但我不想自己麻烦地进行此计算,所以我想知道是否有一种简单的方法可以做到这一点(也许在 Blend 中)
my question is simple.
how can I convert this code:
<Path>
<Path.Data>
<EllipseGeometry Center="5,4" RadiusX="4" RadiusY="4"/>
</Path.Data>
</Path>
into something like
<Path Data="M 0 5 L 3 10 10 0"/>
(please note that the second one produces a checkmark, not an ellipse. It was just for illustration purposes, and my goal is just that: find what sequence gives an ellipse)
edit: I also read the doc about Bezier curves in xaml and am fully aware that I could simply produce the right code by calculating the exact points of the Bezier curve to get an ellipse, but I do not wish to go to the hassle of doing this calculation myself, so I was wondering if there is an easy way to do this (in Blend maybe)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这展示了如何从代码中做到这一点。我不确定这是否能解决你的问题 - 你说“混合?”在标题中,我不知道如何在 Blend 中做到这一点。但我希望这会有所帮助。
第一步是将
EllipseGeometry
转换为PathGeometry
:获得
PathGeometry
后,您只需调用ToString< /code> ,它会给你字符串表示形式:
在我的系统上,这会产生以下相当详细的文本:
“M9,4C9,6.20913899932317 7.20913899932317,8 5,8 2.79086100067683,8 1,6.20913899932317 1,4 1,1.79 086100067683 2.79086100067683 ,0 5,0 7.20913899932317,0 9,1.79086100067683 9,4z"
现在,如果您希望最终得到将该字符串输入到 Xaml 中所得到的结果,则还需要一步,因为 Xaml 的形式您提供的:
不会生成
PathGeometry
。它生成一个 StreamGeometry,这是一种稍微高效但固定的路径表示形式。 (主要区别在于,您无法在StreamGeometry
中获取代表各种图形和分段的单个对象,而使用PathGeometry
则可以。StreamGeometry
更便宜,因此。)您可以从路径文本中获取
StreamGeometry
:然后,如果您希望在
Path
中构建它:取决于根据您的确切目标,可能有更有效的方法来做到这一点。 (
StreamGeometry
是一种更有效的表示形式,因为它最终创建的对象要少得多。但是我的代码到达该表示形式的路线不是很有效,因此您最好停止使用 <或者,如果您的目标实际上只是获取路径文本,那么PathGeometry
也足以满足您的需求。)This shows how to do it from code. I'm not sure if that'll solve your problem or not - you say "with blend?" in the title, and I'm not aware of a way to do this in Blend. But I hope this may help.
The first step would be to convert the
EllipseGeometry
into aPathGeometry
:Once you've got a
PathGeometry
you can simply callToString
and it'll give you the string representation:On my system, this produces the following rather verbose text:
"M9,4C9,6.20913899932317 7.20913899932317,8 5,8 2.79086100067683,8 1,6.20913899932317 1,4 1,1.79086100067683 2.79086100067683,0 5,0 7.20913899932317,0 9,1.79086100067683 9,4z"
Now if you want to end up with exactly what you would have got if you'd fed that string into Xaml, you need one more step, because Xaml of the form you've supplied:
doesn't produce a
PathGeometry
. It produces aStreamGeometry
, which is a slightly more efficient, but fixed representation of the path. (The main difference being that you can't get hold of individual objects representing the various figures and segements in aStreamGeometry
, whereas you can with aPathGeometry
.StreamGeometry
is cheaper, as a result.)You can get a
StreamGeometry
from the path text:And then if you want that in a
Path
just build it:Depending on what your exact goal is, there may be more efficient ways to do this. (
StreamGeometry
is a more efficient representation because it ends up creating far fewer objects. But the route by which my code gets to that representation is not very efficient, so you might be better off just stopping with thePathGeometry
that the very first code snippet produces. Alternatively, if your goal is really just to get the path text, then thePathGeometry
is also sufficient for your needs.)