views:

111

answers:

1

Is there a way to specify how an image is scaled up in an Image element with LayoutTransform set to a ScaleTransform with integer values for ScaleX and ScaleY?

I want to display the scaled image crisply (ie using 'nearest neighbour' scaling), with no blurring. (Imagine how you would want a bitmap editing program to behave when zooming in).

I noticed the protected property VisualBitmapScalingMode on Image, so created a subclass of Image that sets this property to BitmapScalingMode.NearestNeighbor. However, this had no effect.

+1  A: 

I fixed this by overriding OnRender in my Image subclass, and setting the VisualBitmapScalingMode before drawing the image:

class MyImage : System.Windows.Controls.Image
  {
    protected override void OnRender(DrawingContext dc)
    {
      this.VisualBitmapScalingMode = System.Windows.Media.BitmapScalingMode.NearestNeighbor;
      base.OnRender(dc);
    }
  }
mackenir