Converting APNG with transparency to animated GIF - Transparency is lost

sample.zip (368.2 KB)

I’m trying to convert this ^ APNG image to GIF.

static void Main(string[] args)
    {
        string inputPath = @"C:\Concierge\sample.apng";
        string outputPath = @"C:\Concierge\sample.gif";
        
        using (Image apngImage = Image.Load(inputPath))
        {
            var saveOptions = new GifOptions()
            {
            };
            apngImage.Save(outputPath, saveOptions);
        }
        
        if (File.Exists(outputPath))
        {
            System.Console.WriteLine("OK");
        }
    }

The conversion works but the transparency in the APNG isn’t preserved. How can I fix that?

Hello, @nielsbosma ,
Let us review the attached case. You will be answered shortly!

@nielsbosma ,
As for now here is a workaround for this case:

string inputPath = @"C:\Users\Denis\Downloads\sample.apng";
string outputPath = inputPath+ ".gif";
using (var apngImage = Image.Load(inputPath) as RasterCachedMultipageImage)
{
    var pages = apngImage.Pages.Select(p => p as RasterImage);
    foreach (var page in pages)
    {
        page.HasTransparentColor = true;
    }
    apngImage.Save(outputPath);
}

We have also created a ticket to enhance export behavior for transparent multipage raster images:

Issue ID(s): IMAGINGNET-6805
1 Like

Thanks, that workaround works.