首先需要一个 DLL 文件:
Gif.Components.dll
GIF 逐帧转 PNG 图片的代码如下:
string directoryPath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath);
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
GifDecoder gifDecoder = new GifDecoder();
gifDecoder.Read(filePath);
for (int index = 0, count = gifDecoder.GetFrameCount(); index < count; index++)
{
Image frame = gifDecoder.GetFrame(index);
frame.Save(directoryPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + "_" + index + ".png", ImageFormat.Png);
}