How to create Gif .net Core2 , with ImageSharp

喜夏-厌秋 提交于 2019-12-07 23:23:02

问题


Is the any way to create a gif from some jpegs in .net core2 with ImageSharp?

I could create a gif from some jpegs with Magick.Net, but it does'n t work on Linux.

I wanna do this on Ubuntu 14.

EDIT

I could create a Gif from Jpegs with ImageSharp. This is my source code:

        var ite = fsArray.GetEnumerator(); // fsArray is FileStream Array
        ite.MoveNext();
        using (var image1 = Image.Load(ite.Current.Name))
        {
            image1.Mutate(x => x.Resize(width, height));

            // loop
            while (ite.MoveNext())
            {
                using (var image2 = Image.Load(ite.Current.Name))
                {
                    image2.Mutate(x => x.Resize(width, height));
                    image2.Frames.First().MetaData.FrameDelay = interval;
                    image1.Frames.AddFrame(image2.Frames.First());
                }
            }
            msGif = new FileStream("result.gif", FileMode.CreateNew);
            var gifEnc = new SixLabors.ImageSharp.Formats.Gif.GifEncoder();
            image1.Save(msGif, gifEnc);
            msGif.Close();
        }

回答1:


  1. Load your two images
  2. Add the first frame from the second image (after scaling) as an ImageFrame<T> to the Frames property on the first image.
  3. Save the output image as a gif.

Quantization automatically happens when saving the image as a gif. Currently a separate palette will be generated for each frame.

using (var image1 = Image.Load(instream1))
using (var image2 = Image.Load(instream2))
{
  image2.Mutate(x => x.Resize(image1.Width, image1.Height));
  image1.Frames.AddFrame(image2.Frames[0]);

  image1.Save(outstream, new GifEncoder());
}


来源:https://stackoverflow.com/questions/48577742/how-to-create-gif-net-core2-with-imagesharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!