【问题标题】:How to turn off anti-aliasing for DrawingBrush?如何关闭 DrawingBrush 的抗锯齿功能?
【发布时间】:2011-05-07 13:34:44
【问题描述】:

我想画一个三角形作为边框背景。一种方法是使用 DrawingBrush,但在较小的尺寸下,抗锯齿会扭曲三角形并使其模糊。 如何禁用抗锯齿功能?

<Border>
    <Border.Background>
        <DrawingBrush>
            <DrawingBrush.Drawing>
                <GeometryDrawing Brush="Red">
                    <GeometryDrawing.Geometry>
                        <PathGeometry>
                            <PathGeometry.Figures>
                                <PathFigureCollection>
                                    <PathFigure IsClosed="True" StartPoint="0,3" IsFilled="True">
                                        <PathFigure.Segments>
                                            <LineSegment Point="3,0" />
                                            <LineSegment Point="6,3" />
                                        </PathFigure.Segments>
                                    </PathFigure>
                                </PathFigureCollection>
                            </PathGeometry.Figures>
                        </PathGeometry>
                    </GeometryDrawing.Geometry>
                </GeometryDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Border.Background>
</Border>

我已尝试在所有可能的元素上设置 RenderOptions.EdgeMode="Aliased" 和 SnapsToDevicePixels="true",但没有奏效...

编辑:
这就是 Width=17 时绘制的三角形的样子;高度=12(放大到 800%):

如您所见,边缘已消除锯齿。禁用抗锯齿的所有常用选项似乎都不起作用...

【问题讨论】:

  • 您能否提供一张截图(以及您使用的宽度/高度值)?
  • @H.B.检查我的帖子的编辑

标签: wpf


【解决方案1】:

我也对此感到非常沮丧。经过一番研究,我找到了答案:使用 Visual Brush 并将视觉中的 Image 元素设置为 SnapToDevicePixels = true 和 Aliased Edge Mode。请看下面的例子:

            <Canvas VerticalAlignment="Top" Height="12" Margin="0,24,0,0">
                <Canvas.Background>
                    <VisualBrush  TileMode="Tile"  Stretch="None" Viewport="-5,0,10,10" ViewportUnits="Absolute">
                        <VisualBrush.Visual>
                            <Image Stretch="None" RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="True">
                                <Image.Source>
                                    <DrawingImage>
                                        <DrawingImage.Drawing>
                                            <GeometryDrawing>
                                                <GeometryDrawing.Pen>
                                                    <Pen Brush="#8F8E8F" Thickness="1" />
                                                </GeometryDrawing.Pen>
                                                <GeometryDrawing.Geometry>
                                                    <LineGeometry StartPoint="0,0" EndPoint="0,10"/>
                                                </GeometryDrawing.Geometry>
                                            </GeometryDrawing>
                                        </DrawingImage.Drawing>
                                    </DrawingImage>
                                </Image.Source>
                            </Image>
                        </VisualBrush.Visual>
                    </VisualBrush>
                </Canvas.Background>
            </Canvas>

【讨论】:

  • 这是很久以后的事了,但我发现这是一个完美的解决方案! .Net4.61、VS2017
【解决方案2】:

考虑到没有更多的回复,那么答案似乎是——不可能。

【讨论】:

    【解决方案3】:

    我认为您应该能够使用 SnapToDevicePixels 来做到这一点(尽管有时需要一些尝试和错误)。您应该将其设置在拥有的对象上(因此无论放入什么边框)。你读过这篇文章吗? http://msdn.microsoft.com/en-us/library/aa970908.aspx

    【讨论】:

    • 我尝试在所有可能的元素上设置 SnapToDevicePixels,从窗口一直到边框本身,但它不起作用。可能是因为 DrawingBrush 和它的孩子没有那个属性......由于某种原因,似乎 RenderOptions.EdgeMode="Aliased" 不被 DrawingBrush 和它的孩子所尊重,所以这也不起作用。我已阅读您链接的文章,但遗憾的是它在这种特定情况下没有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 2023-04-07
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    相关资源
    最近更新 更多