How to turn off the anti-aliasing in WPF shapes?
Asked Answered
K

3

19

I draw a rectangle using:

<Rectangle Width="300" Height="100" Stroke="Blue" StrokeThickness="6"> </Rectangle>

but there is anti-aliasing applied to it. Is there a way to turn this off? I want it to be sharp and clear.

Khartoum answered 7/4, 2011 at 17:26 Comment(0)
W
25

A little late but RenderOptions.EdgeMode="Aliased" does the trick

<Rectangle Width="300"
           Height="100"
           Stroke="Blue"
           StrokeThickness="6"
           RenderOptions.EdgeMode="Aliased"/>
Wallpaper answered 24/4, 2012 at 18:22 Comment(1)
I have noticed significant performance degradation with this method. Perhaps it is driver bound but I have a suspicion that it falls back to software.Worse
B
5

Check out SnapToDevicePixels: http://msdn.microsoft.com/en-us/library/aa970908.aspx

Bolingbroke answered 7/4, 2011 at 17:31 Comment(1)
This doesn't actually turn off the anti-aliasing. It allows you to force WPF to render graphics to match the device or display matrix, thus prevent blurrying in some cases. The effect is similar to Mac OS X vs. Windows font smoothing.Hamlen
W
4

Turning off anti-aliasing is not what you are looking for, seeing as you dont have a radius applied to the corners.

If you are using .Net 4 or above, turn on UseLayoutRounding http://msdn.microsoft.com/en-us/library/system.windows.uielement.uselayoutrounding(v=vs.95).aspx

Worse answered 23/1, 2013 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.