title: Bitmap cache on DrawingVisual has blurry parts
body: <p>Recently I switched to <code>DrawingVisuals</code> to increase the performance of our trending graphs (especially zooming and panning).</p>
  
  <p>Here's the code I have:</p>
  
  <pre><code>blocksToBeRendered = (baseItem as AvgCurve).GetStreamGeometryBlocks(ActualWidth, ActualHeight, _minPoint.X, _maxPoint.X, FixTimeStep ? _timeStep : 0, IsMainChart);
  
  Pen stroke = new Pen((baseItem as AvgCurve).LineBrush, 1);
  
  foreach (GeometryGroup group in blocksToBeRendered)
  {
      if (group.Children.Count != 0)
      {
          if (!cachedBlocks[baseItem].Any(x =&gt; x.Children[0] == group.Children[0]))
          {
              cachedBlocks[baseItem].Add(group);
  
              ImprovedDrawingVisual vis = new ImprovedDrawingVisual();
  
              BitmapCache cache = new BitmapCache() { SnapsToDevicePixels = true };
              vis.CacheMode = cache;
  
              using (DrawingContext context = vis.RenderOpen())
              {
                  RenderOptions.SetEdgeMode(group, EdgeMode.Aliased);
                  if (group.Children.Count &gt; 0)
                  {
                      context.DrawGeometry(null, stroke, group.Children[0]);
                  }
              }
  
              _host.VisualCollection.Add(vis);
          }
      }
  }
  </code></pre>
  
  <p>This is the <code>ImprovedDrawingVisual</code>:</p>
  
  <pre><code>public class ImprovedDrawingVisual: DrawingVisual
  {
      public ImprovedDrawingVisual()
      {
          VisualEdgeMode = EdgeMode.Aliased;
          VisualBitmapScalingMode = BitmapScalingMode.NearestNeighbor;
      }
  }
  </code></pre>
  
  <p>Now, the geometries do have <code>Transforms</code>, which might be important.</p>
  
  <p>What happens is that the graphs are drawn nicely without bitmap caching (1 px lines), but when I turn on bitmap caching, parts of the graph go all blurry sometimes.</p>
  
  <p><img src="https://i.stack.imgur.com/frYwK.png" alt="blurry lines"></p>
  
  <p>Does anyone know how I can fix this? I tried changing the <code>RenderAtScale</code> of the <code>DrawingVisual</code> or turning off the <code>EdgeMode</code> setting, but that doesn't help.</p>
  
  <p><strong>EDIT:</strong> Left out the brush fill geometry to avoid confusion since it's not relevant here.</p>