WPF:如何将 GeneralTransform 应用于几何数据并返回新的几何图形?
有了一些几何数据和变换,如何将变换应用于几何以获得数据变换后的新几何?
例如:我有一个 Path 对象,其 Path.Data 设置为 PathGeometry 对象,我想使用变换就地变换 PathGeometry 对象的点,并且不对渲染时使用的 PathGeometry 应用变换。
PS 我知道 Transform 类有一个方法 Point Transform.Transform(Point p)
,可用于变换 Point 但是......有没有办法立即变换任意几何图形?
编辑: 请参阅我的回复,了解当前找到的 解决方案
Having some Geometry data and a Transform how can the transform be applied to the Geometry to get a new Geometry with it's data transformed ?
Ex: I Have a Path object that has it's Path.Data set to a PathGeometry object, I want to tranform the points of the PathGeometry object in place using a transform, and not apply a transform to the PathGeometry that will be used at render time.
P.S. I know that the Transform class has a method Point Transform.Transform(Point p)
that can be used to transform a Point but...is there a way to transform a arbitrary geometry at once?
Edit:
See my repply for a currently found solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我找到了一种可以将任意变换应用于路径几何图形的解决方案,这要归功于 Todd White 的回答:
基本上 Geometry.Combine 用于使用 Union 将所需的几何图形与 Geometry.Empty 组合在一起,并且给出了所需的变换。 生成的几何图形将使用给定的变换进行变换。
I've found a solution with which arbitrary tranform can be applied to a path geometry, thanks to Todd White's answer:
Basically Geometry.Combine is used to combine the desired geometry with Geometry.Empty using Union, and the desired transform is given. The resulting geometry is transformed with the given transform.
您可以尝试使用 Geometry.Combine。 它在组合期间应用变换。 一个问题是,只有当您的几何体有面积时,“组合”才起作用,因此单线不起作用。
这是一个对我有用的示例。
You could try and use Geometry.Combine. It applies a transform during the combine. One catch is that Combine only works if your Geometry has area, so single lines will not work.
Here is a sample that worked for me.
我发现您可以这样做来获得所有图形信息完好无损的转换后的几何图形:
This is what I found you can do to get a transformed geometry with all of the figure information intact:
我没有使用接受的答案,因为它返回的几何图形格式与原始格式不同,所以我使用了这个:
I didn't use accepted answer since it was returning geometry in format different from the original one, so I used this:
对于由单个 LineElement 构成的路径,基于 Geometry.Combine 的快速解决方案都不起作用。
所以我用困难的方式解决了这个问题,就像这样(但我也仅限于 PathGeometry):
None of the quick solutions based on Geometry.Combine works in the case of path made of a single LineElement.
So I solved the problem the hard way, like this (But I am also limited to PathGeometry):
不幸的是,我认为没有一种方法或属性可以满足您的要求。 至少,我找不到一个。 (好问题!)
看来您必须手动执行此操作(正如您自己建议的那样)...即为 PathGeometry 中的每个点调用 Point Transform.Transform(Point p) ..在此过程中创建一个新的 PathGeometry。
可能不是你想要的答案。 (悔恨的笑容)
Unfortunately, I don't think there is a method or property to do what you are asking. At least, I can't find one. (Great question!)
It seems like you would have to do it manually (as you suggest yourself) ... that is call Point Transform.Transform(Point p) for every point in your PathGeometry ... creating a new PathGeometry in the process.
Probably isn't the answer you want. (Rueful Grin)
我遇到了同样的问题并且也需要线条(不仅仅是具有面积的几何图形)。
我只使用 PathGeometry,所以这可能不是您正在寻找的通用解决方案,但这对我有用:
I've had the same problem AND need lines as well (not only geometries with area).
I'm only using PathGeometry, so this may not be the general solution you are looking for, but this worked for me:
您必须考虑两件事:
There are two things you have to consider: