C#从Gif中提取图片的代码片段

private void btn_extract_Click(object sender, EventArgs e)
{
Image imgGif = Image.FromFile(@"test.gif", true); //Create a new FrameDimension object from this image
var ImgFrmDim = new FrameDimension(imgGif.FrameDimensionsList[0]); //Determine the number of frames in the image
//Note that all images contain at least 1 frame,
//but an animated GIF will contain more than 1 frame. int n = imgGif.GetFrameCount(ImgFrmDim); // Save every frame into jpeg format
for (int i = 0; i < n; i++)
{
imgGif.SelectActiveFrame(ImgFrmDim, i);
imgGif.Save(string.Format(@"Frame{0}.png", i), ImageFormat.Png);
}
}
05-08 15:13