How to convert animated gif to another image format in .NET?

Hi,
I am working with GroupDocs.Conversion in conjunction with another web-based previewing technology. I have an animated gif that I would like to convert to a PNG so that it’s previewable in this web-based viewer control (it currently doesn’t support gifs)
I have c# code that I can use to determine if the image contains multiple frames (ie - is animated), but I was wondering if GroupDocs.Conversion could handle extracting the first frame from the animated gif, or if that was something I had to write myself.
Looking here:

I was able to successfully upload my animated gif, and the converted file I received is the first frame of the animated gif, but as a png, which is exactly what I want. Is that behavior native to GroupDocs.Conversion? or is that custom code that you wrote?

Thanks,
-Brian

1 Like

@bpieslak,

You can convert an animated GIF file to another image (e.g. PNG). For example, converting this.zip (27.0 KB) GIF to PNG will give you this output.png (11.8 KB).

Yes, API will extract first frame and give you output just like this app Online GIF to PNG Converter | Free GroupDocs Apps.
Given below is the code for such a type of conversion:

string outputFileTemplate = Path.Combine(@"D:/Samples/Output/", "Converted-page={0}.png");
SavePageStream getPageStream = page => new FileStream(string.Format(outputFileTemplate, page), FileMode.Create);
using(Converter converter = new Converter(@"D:/Samples/sample.gif"))
{
    ImageConvertOptions options = new ImageConvertOptions
    {
        Format = ImageFileType.Png
    };
    converter.Convert(getPageStream, options);
}

.
You can get further details in this documentation article and download API here.

fantastic. thank you so much!
-Brian

1 Like

@bpieslak,

You are welcome.