1

I have tried like this but APNG animation is lost

Also I am looking for settings to lossless yet maximum compression. I don't care about CPU time speed etc. I need lossless and maximum compression. how to achieve that?

So I have a lot of PNG files and some APNG files

I will turn all of them into WEBP files

Yet I still want to keep APNG animation as well

Here example APNG to test : https://static.pokemonpets.com/images/npcTrainers/trainer15125down.png

     using (var image = new MagickImage(@"path\Debug\a.png"))
        {
            image.Quality = 100;
            image.Settings.SetDefine(MagickFormat.WebP, "lossless", true);
            image.Settings.SetDefine(MagickFormat.WebP, "method", "6");
            image.Write("a.webp");
        }

C# .net framework 4.8, Magick.NET-Q16-AnyCPU, 7.24.1.0

Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342

1 Answers1

2

If you want to read an image that contains multiple frames you will need to use the MagickImageCollection instead:

using (var images = new MagickImageCollection(@"apng:path\Debug\a.png"))
{
    var defines = new WebPWriteDefines
    {
        Lossless = true,
        Method = 6,
    };

    images.Write("a.webp", defines);
}

And if you want to read an animated PNG file you will need to have ffmpeg.exe in your %PATH%. This is required to read an animated PNG file. And you will also need to add apng: to make sure that ImageMagick knows that it is an animated PNG file.

dlemstra
  • 7,813
  • 2
  • 27
  • 43
  • ty for answer but still lacking. it requires to initialize like this : FileInfo img_apng = new FileInfo(srWorkingDirectory + @"\test\trainer15202down.png"); using (var images = new MagickImageCollection(img_apng, MagickFormat.APng)) – Furkan Gözükara Jun 24 '21 at 18:25