C#从Gif中提取图片


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);
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM