title: How to show avif format image in wpf?
body: <p>I solved the webp problem by posting <a href="https://stackoverflow.com/questions/65288683/how-to-display-webp-format-image-in-wpf">this</a> question before. However, the avif extension is still unresolved.<br><br>
  I would like to display the image of <a href="http://www.imageview.kro.kr/images/test.avif" rel="nofollow noreferrer">this</a> avif extension using BitmapImage in wpf image control.<br>
  However, BitmapImage does not support avif extensions and does not display.<br>
  <br>
  Then how can you display an image of avif?<br>
  Below is the code I've worked on so far.</p>
  <pre class="lang-cs prettyprint-override"><code>private static BitmapImage LoadImage(byte[] imageData, string ext) {
    if (imageData == null || imageData.Length == 0) return null;
    var image = new BitmapImage();
    using(var mem = new MemoryStream(imageData)) {
      mem.Position = 0;
      image.BeginInit();
      image.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
      image.CacheOption = BitmapCacheOption.OnLoad;
      image.UriSource = null;
      if (ext == &quot;webp&quot;) {
        SimpleDecoder dec = new SimpleDecoder();
        dec.DecodeFromBytes(imageData, imageData.Length).Save(mem, System.Drawing.Imaging.ImageFormat.Png);
        image.StreamSource = mem;
      } else if (ext == &quot;avif&quot;) {
        //TODO: display avif format image
      }
      else {
        image.StreamSource = mem;
      }
      image.EndInit();
    }
    image.Freeze();
    return image;
  }
  
  using(WebClient wc = new WebClient()) {
    Byte[] Mydata = wc.DownloadData(&quot;http://www.imageview.kro.kr/images/test.avif&quot;);
    //The address in this code is a temporary created address,
    //but the actual address requires a header request. So I use WebClient.
    Console.WriteLine(Mydata.Length);
    wc.Dispose();
    Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate {
      thumbnail.Source = LoadImage(Mydata, &quot;avif&quot;);
    }));
  }
  </code></pre>