Resizing images with WPF 4.0
Microsoft changed the default behaviour for scaling images with WPF 4.0/.NET 4.0.
They opted for a faster but less accurate scaling algorithm named Linear instead of the default Fant that was used in WPF 3.0.
You can change this behaviour using the RenderOptions.BitmapScalingMode attached property.
Microsoft recommends to only use HighQuality if the image’s scaled size will be less that 30-50% of the original size.
The Resizer application will always use HighQuality so that it gives the best image quality for any image.
Using the attached property on images scaled in code using DrawingVisual/RenderTargetBitmap requires a bit of special code.
Width and height contains the margin already, so if the image is scaled to 300px with a margin of 10px then the method will be called with width = 320px and margin = 10px. We can use the DrawingGroup to set the BitmapScalingMode and then add the ImageDrawing to it.