title: XAML Image Quality (interpolation) in a Metro-Style App
body: <p>Given the following Image object (it's in the DataTemplate of a ListView object):</p>
  
  <pre><code>  &lt;Image Source="{Binding ImgSource}" ImageOpened="img_ImageOpened" /&gt;
  </code></pre>
  
  <p>how am I supposed to get an high-quality bicubic-interpolated image? (on screen, the size of this Image is smaller than the source PNG, but the default resizing appears to be performed with the poor-quality "nearest neighbor" interpolation).</p>
  
  <p>Since I would like to rely on data binding alone (whenever the ImgSource of the associated data item changes, the Image content should change), I've tried to set an ImageOpened handler and change the just-loaded image to a better-quality one.</p>
  
  <p>Unfortunately, the code below seems not to work (I just get empty images):</p>
  
  <pre><code>    async void LoadImage(Image imgControl, string source)
      {
          try
          {
              StorageFile file = await StorageFile.GetFileFromPathAsync(source);
  
              IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read);
              BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);
  
              InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
              BitmapEncoder enc = await BitmapEncoder.CreateForTranscodingAsync(ras, decoder);
  
              enc.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Cubic;
              enc.BitmapTransform.ScaledHeight = Convert.ToUInt32(imgControl.ActualHeight);
              enc.BitmapTransform.ScaledWidth = Convert.ToUInt32(imgControl.ActualWidth);
  
              await enc.FlushAsync();
  
              Windows.UI.Xaml.Media.Imaging.BitmapImage bImg = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
              bImg.SetSource(ras);
              imgControl.Source = bImg;
          }
          catch (Exception e)
          {
              return;
          }
      }
  
      void img_ImageOpened(object sender, RoutedEventArgs e)
      {
          Image imgControl = (Image)sender;
          LoadImage(imgControl, &lt;path to PNG file&gt;);
      }
  </code></pre>