将 RenderTransform 应用于 EllipseGeometry

发布于 2024-12-20 22:03:16 字数 1238 浏览 0 评论 0原文

我希望将 RenderTransform 的内容应用于 EllipseGeometry 的物理属性,这意味着 EllipseGeometry 的 Center/RadiusX/RadiusY 属性会通过应用变换而更改。我这样做的原因是,我有一个绘图程序,您可以在其中绘制椭圆,绘制后您可以缩放/旋转/平移椭圆,在幕后我将其应用为原始 Path 对象上的 RenderTransforms(其“Data “属性是一个 EllipseGeometry 对象)。目前,对于我的绘图程序中的其他几何图形(贝塞尔曲线、直线、圆弧等),当需要将数据保存到文件时,我使用以下方法来应用 RenderTransforms。

    Geometry clone = linePath.Data.Clone();
    clone.Transform = linePath.RenderTransform(); //Which is a TransformGroup in my case
    Geometry transformedGeometry = clone.GetFlattenedPathGeometry();

这给我留下了一个干净的几何体,“linePath”的 RenderTransform 已应用到该几何体上。现在,我可以轻松地将此几何体的内容保存到“迷你语法”中的文件中,并在稍后重新加载。我知道我可以对 EllipseGeometry 使用相同的方法,但结果是描述翻译后的 EllipseGeometry 的近似 PathGeometry,并且当我从文件重新加载数据时,我不知道如何将该结果转换回 EllipseGeometry。目前,对于绘图中的 EllipseGeometry 对象,我保存物理属性(中心/半径/等),然后将相应的 RenderTransform 作为 XAML 字符串保存到文件中。然后在加载时,我只需从属性创建 EllipseGeometry 并应用保存的 RenderTransform。

现在,这种方法有效,但我觉得保存翻译后的椭圆几何形状会更干净,就像我在其他几何形状的情况下所做的那样。我还在我的应用程序中的其他地方使用了 RenderTransforms 作为 EllipseGeometries 的物理转换,并且解决方法变得越来越丑陋,所以我想确定一个执行此操作的过程(如果可能的话)。

提前致谢!

编辑: 只是为了让问题更加开放,我不致力于使用 EllipseGeometry,因为我不明白它如何用于描述 RenderTransform 中可能存在的所有不同转换(即旋转)。因此,如果有其他方法或其他几何形状可以用来提供“类似椭圆”的行为,我肯定有兴趣听到它。

I'm looking to apply the contents of a RenderTransform to the physical properties of an EllipseGeometry, meaning that the Center/RadiusX/RadiusY properties of the EllipseGeometry are changed by the application of the transform. My reason for doing this is, I have a drawing program in which you can draw ellipses and after drawing you are allowed to scale/rotate/translate the ellipse, which under the hood I apply as RenderTransforms on the original Path object (whose "Data" property is an EllipseGeometry object). Now currently, for other geometries in my drawing program (bezier curves, lines, arcs, etc) I use the following approach to apply the RenderTransforms when it comes time to save the data to a file.

    Geometry clone = linePath.Data.Clone();
    clone.Transform = linePath.RenderTransform(); //Which is a TransformGroup in my case
    Geometry transformedGeometry = clone.GetFlattenedPathGeometry();

This leaves me with a clean geometry onto which the RenderTransform of the "linePath" has been applied. Now I can easily save the contents of this geometry to a file in "Mini Syntax" and reload it at a later time. I know I can use the same approach for an EllipseGeometry, but the result is an approximated PathGeometry describing the translated EllipseGeometry and I don't know of a way of converting that result back into an EllipseGeometry when I reload the data from a file. Currently, for the EllipseGeometry objects in a drawing I save the physical properties (Center/Radius/etc) and then save the corresponding RenderTransform as a XAML string to file. Then on load I just create the EllipseGeometry from the properties and apply the saved RenderTransform.

Now, this approach works, but I feel it would be cleaner to save the translated ellipse geometry as I do in the case of other geometries. I also have uses elsewhere in my application for applying RenderTransforms as physical transformations to EllipseGeometries and the workarounds are getting uglier and uglier, so I'd like to nail down a process for doing this (if it is even possible).

Thanks in advance!

EDIT:
Just to make the question a little more open, I'm not committed to using EllipseGeometry, since I don't see how it could possibly be used to describe all of the different transformations that can be present in a RenderTransform (i.e. Rotate). So if there is some other way or some other geometry that could be used that provides "ellipse-like" behavior, I'd definitely be interested in hearing about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文