Create a Gif file, but this is not a loop

I am using the GifBitmapEncoder class to generate a gif file. Create success, but it's not a 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);
        }
    }
}

      

+3


source to share





All Articles