4

I use the GifBitmapEncoder Class to Create a gif File. Create Success , But it is not Loop.

my code:

private string[] _files = null;
private void CreateGifFile()
{
    if (_files != null && _files.Length != 0)
    {
        GifBitmapEncoder gEncoder = new GifBitmapEncoder();
        _files.ToList().ForEach((a) =>
        {
            Bitmap bitmap = new Bitmap(a);
            var src = Imaging.CreateBitmapSourceFromHBitmap
            (
                    bitmap.GetHbitmap(),
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions()
            );
            gEncoder.Frames.Add(BitmapFrame.Create(src));
        });

        using (var fileStream = new FileStream ("1.gif", FileMode.Create))
        {
            gEncoder.Save(fileStream);
        }
    }
}
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
sunth
  • 77
  • 3

0 Answers0