Image Resize Aliasing in WPF v4, but not under v3.5

I use WPF for the image resizing pipeline that works great under .NET v3.5. I just upgraded the project to the target version 4.0, and now all my changed images are very smooth. None of the image pipeline code has changed.

  • Is the default WPF option set between v3.5 and v4.0?

  • How to control anti-aliasing of my modified bitmaps in WPF?

I use the BitmapImage, DrawingVisual, DrawingContext, RenderTargetBitmap, BitmapEncoderand BitmapFrame, but I do not see any properties associated with the smoothing. GDI + had a bunch of settings, so I guess something is missing.

Update: it looks like all the solutions I've seen assume a Window object or XAML environment. This is done inside a Windows service that does not have a user interface. I need a way to programmatically affect this parameter.

I specifically switched from GDI + to WPF, because GDI + has memory leaks in lengthy processes like services and web applications.

+5
source share
2 answers

The only way to influence the setting BitmapScalingModeis to inherit from the class DrawingVisualand install it through the protected accessor:

// exposes BitmapScalingMode (also works for other protected properties)
public class MyDrawingVisual : DrawingVisual
{
    public BitmapScalingMode BitmapScalingMode
    {
        get { return this.VisualBitmapScalingMode; }
        set { this.VisualBitmapScalingMode = value; }
    }
}

If anyone else knows of a better way to fix this, I would love to hear about it.

This seems to work:

RenderOptions.SetBitmapScalingMode(myDrawingVisual, BitmapScalingMode.HighQuality);

... . , XAML , .

+3

BitmapScalingMode Fant 3.0, 4.0 BiLinear. -. .

+1

All Articles