Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF resize anti-aliasing artifacts on Windows Server 2003
    text
    copied!<p>I am resizing PNG’s in a console app using the following WPF code in .NET 4:</p> <pre><code>const int width = 250; const int height = 179; DrawingGroup group = new DrawingGroup(); RenderOptions.SetBitmapScalingMode(group, BitmapScalingMode.Fant); group.Children.Add(new ImageDrawing(source, new Rect(0, 0, width, height))); DrawingVisual targetVisual = new DrawingVisual(); using (DrawingContext targetContext = targetVisual.RenderOpen()) { targetContext.DrawDrawing(group); targetContext.Close(); RenderTargetBitmap target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default); target.Render(targetVisual); BitmapSource resized = BitmapFrame.Create(target); } </code></pre> <p>When running on Windows 7 this works exactly as expected, but when running on Windows Server 2003 I get what I think are anti-aliasing artefacts.</p> <p><a href="http://i.stack.imgur.com/wQfUp.jpg" rel="nofollow">This Image</a> shows how, when displayed on a web page with a white background, the Server 2003 image has extra horizontal and vertical grey lines in the white area that should not be there.</p> <p>Zooming in on one small section to try and work out what is happening <a href="http://i.stack.imgur.com/r7ljo.jpg" rel="nofollow">this image</a> shows how the original PNG has a 1 pixel semi-transparent line between the transparent section (shown as chequered grey and white) and the white area. Both resized images have the same semi-transparent line but the one under Server 2003 has some weird variations in the level of transparency.</p> <p>There is a good MSDN document on the effects of anti-aliasing when resizing images in WPF (http://msdn.microsoft.com/en-us/library/aa970908.aspx) that would seem to match the symptoms I am seeing here but why would this work differently between Windows 7 and Server 2003??</p> <p>I have tried to find ways to switch of anti-aliasing to test this theory using the following code but it didn’t make any difference:</p> <pre><code>RenderOptions.SetEdgeMode(group, EdgeMode.Aliased); </code></pre>
 

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