开发者

How to turn off anti-aliasing for DrawingBrush?

I want to draw a triangle as a border background. One way of doing this is by using a DrawingBrush, but at smaller sizes anti-aliasing is distorting the triangle and making it blurry. How can I disable anti-aliasing?

<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开发者_StackOverflow社区>
                </GeometryDrawing>
            </DrawingBrush.Drawing>
        </DrawingBrush>
    </Border.Background>
</Border>

I've tried setting RenderOptions.EdgeMode="Aliased" and SnapsToDevicePixels="true" on all possible elements, but that hasn't worked...

Edit:

This is what the drawn triangle looks like at Width=17; Height=12 (zoomed to 800%):

How to turn off anti-aliasing for DrawingBrush?

As you can see the edges are anti-aliased. All the usual options for disabling anti-aliasing don't seem to be working...


I also became very frustrated with this. After some research, I found the answer: Using a Visual Brush with the Image element in the visual set to SnapToDevicePixels = true and Aliased Edge Mode. See the example below:

            <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>


Considering there haven't been any more replies, then it seems that the answer is - it's impossible.


I think you should be able to do it with SnapToDevicePixels (although sometimes it takes a little trial and error). You should set it on the owning object (so whatever the border is being put in). Have you read this article? http://msdn.microsoft.com/en-us/library/aa970908.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜