How to make AVIF codec a dependency of ASP.NET Web project with SkiaSharp?

195 Views Asked by At

It looks like SkiSharp supports Avif. I'm on Windows 10. I see in this PR that the Avif enum value was added to the SKEncodedImageFormat enum.

However when I run the code below with SKEncodedImageFormat.Avif it fails. The SKData value is null.

static void SaveBitmapAsAvif(SKBitmap bitmap, string filePath, int quality = 80) {
      
      //create an image from the bitmap
      using (SKImage image = SKImage.FromBitmap(bitmap)) {
          
          SKEncodedImageFormat skiaFormat = SKEncodedImageFormat.Avif; 
          

          SKData data = image.Encode(skiaFormat, quality);
          //data is null here!

          using (FileStream output = new FileStream(filePath, FileMode.Create, FileAccess.Write)) {
              data.SaveTo(output);
          }
      }
  }

Yet this code works fine with every other SKEncodedImageFormat value I have tried.

I think a related issue is that if I double click o a avif image in windows I'm told I need to download and install the AV1 Video Extension from the windows store.

enter image description here

Althought interestingly, If I drag the avif file into the Chrome browser, it will render just file. So at least Chrome as access to a codec for AVIF on my machine.

Still, more than likely if I did install the SkiaSharp codec from the Microsoft store SkiaSharp would like be able to save an image as a avif file.

However, I'm using SkiaSharp in the context of ASP.NET 8 web application and I want the skia codec deployed with my solution. I don't want to do some separate install of the avif codec on the server.

How can I make the AVIF codec a dependency of my ASP.NET 8 Project so that when I publish the solution the codec is deployed with the rest of the solution?

0

There are 0 best solutions below