如何为使用 WPF StreamGeometry 绘制的折线启用抗锯齿功能?

发布于 2024-09-06 08:11:49 字数 516 浏览 3 评论 0原文

我需要在 DrawingVisual 中绘制一条折线。出于性能原因,我使用 StreamGeometry。我遇到的问题是我不知道如何启用抗锯齿功能。我在 StreamGeometry 或 DrawingContext 上找不到任何用于抗锯齿控制的方法或属性。

下面的代码是在 IronPython 中,但这并不重要:

geometry = StreamGeometry()
context = geometry.Open()
context.BeginFigure(Point(10, 10), False, False)
context.LineTo(Point(100, 100), True, False)
context.LineTo(Point(200, 300), True, False)
context.Close()

dv = DrawingVisual()
dc = dv.RenderOpen()
dc.DrawGeometry(None, Pen(Brushes.Blue, 1), geometry)
dc.Close()

I need to draw a polyline into a DrawingVisual. I'm using StreamGeometry for performance reasons. The problem I have is that I can't figure out how to enable anti-aliasing. I can't find any method or property on StreamGeometry or on DrawingContext for anti-aliasing control.

The code below is in IronPython, but it shouldn't matter:

geometry = StreamGeometry()
context = geometry.Open()
context.BeginFigure(Point(10, 10), False, False)
context.LineTo(Point(100, 100), True, False)
context.LineTo(Point(200, 300), True, False)
context.Close()

dv = DrawingVisual()
dc = dv.RenderOpen()
dc.DrawGeometry(None, Pen(Brushes.Blue, 1), geometry)
dc.Close()

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2024-09-13 08:11:49

要禁用抗锯齿功能,您可以使用 RenderOptons 类,具有静态方法 SetEdgeMode 可以确定 DependencyObject 的非文本绘制基元的边缘如何呈现。

RenderOptions.SetEdgeMode(MyDependencyObject, EdgeMode.Aliased)

希望这有帮助。

To disable anti-aliasing you could use RenderOptons class, with the static method SetEdgeMode it's possible to determine how the edges of non-text drawing primitives of your DependencyObject are rendered.

RenderOptions.SetEdgeMode(MyDependencyObject, EdgeMode.Aliased)

Hope this help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文