如何为使用 WPF StreamGeometry 绘制的折线启用抗锯齿功能?
我需要在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要禁用抗锯齿功能,您可以使用 RenderOptons 类,具有静态方法 SetEdgeMode 可以确定 DependencyObject 的非文本绘制基元的边缘如何呈现。
希望这有帮助。
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.
Hope this help.