How do you get the individual images of animated gif?



  • There's animated gif in the file.
    How do we extract the individual personnel (Image) and remove them as a net?



  • using System.Drawing.Imaging;
    using System.Drawing;
    
    static IEnumerable<Image> Frames(Image gif) {
      var d = new FrameDimension(gif.FrameDimensionsList[0]);
      for (var i = 0; i < gif.GetFrameCount(d); i++) {
         gif.SelectActiveFrame(d, i);
         var ci = new Bitmap(gif.Width, gif.Height);
         using (var g = Graphics.FromImage(ci))
            g.DrawImageUnscaled(gif, 0, 0);
         yield return ci;
      }
    }
    
    var f1 = new Form() { Width = 450, Height = 250 };
    var img = Image.FromFile(@"C:\Temp\5-0.gif");
    var t = new TableLayoutPanel() {
                  Parent = f1,
                  BackColor = Color.White,
                  Dock = DockStyle.Fill,
                  AutoSize = false,
                  AutoSizeMode = AutoSizeMode.GrowOnly
                  };
    int ci = 0, ri = 0;
    foreach (var fi in Frames(img)) {
       var p = new PictureBox() { Image = fi, Parent = t };
       t.Controls.Add(p, ci, ri);
       if (++ci == 4) { ci = 0; ri++; }
    }
    f1.ShowDialog();
    

    For rice.

    введите сюда описание изображения

    Got it.

    введите сюда описание изображения




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2