Note that there are some explanatory texts on larger screens.

plurals
  1. POAnti-aliasing artifacts in WPF
    text
    copied!<p>I have a bizarre rendering issue when I'm trying to use anti-aliased graphics in WPF.</p> <p>Here's a simplified version.</p> <p>If I use the following XAML</p> <pre><code>&lt;Window x:Class="RenderingBug.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Width="300" Height="300"&gt; &lt;Grid Name="myGrid" Background="AntiqueWhite" Width="250" Height="250"&gt; &lt;ScrollViewer Name="myScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"&gt; &lt;Canvas Height="500" Width="500" Name="myCanvas" /&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>And the following cs</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace RenderingBug { /// &lt;summary&gt; /// Interaction logic for Window1.xaml /// &lt;/summary&gt; public partial class Window1 : Window { public Window1() { InitializeComponent(); PathFigureCollection pfc = new PathFigureCollection(); PathFigure pf = new PathFigure(); pf.StartPoint = new Point(100, 20); LineSegment ls = new LineSegment(); ls.Point = new Point(20, 100); PathSegmentCollection psc = new PathSegmentCollection(); psc.Add(ls); pf.Segments = psc; pfc.Add(pf); PathGeometry pg = new PathGeometry(pfc); RectangleGeometry clippingRectangle = new RectangleGeometry(new Rect(0, 0, 80, 80)); Path p1 = new Path(); p1.ClipToBounds = true; p1.Clip = clippingRectangle; p1.StrokeDashCap = PenLineCap.Square; p1.Stroke = Brushes.Black; p1.StrokeThickness = 30; p1.Data = pg; myCanvas.Children.Add(p1); Path p2 = new Path(); p2.ClipToBounds = true; p2.Clip = clippingRectangle; p2.StrokeDashCap = PenLineCap.Square; p2.Stroke = Brushes.White; p2.StrokeThickness = 10; p2.Data = pg; myCanvas.Children.Add(p2); } } } </code></pre> <p>I get a strange rendering issue with the anti-aliasing where the cropping rectangle edge is (running the program, it will be fairly obvious, but it's a hazy gray line where the cropping rectangle is truncating the paths.)</p> <p>I've tried various techniques like aligning the controls to specific pixels, and setting SnapsToDevicePixels on the various controls in the hopes that this would solve this issue (remove the extra hazy gray band), but nothing seems to help. </p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload