2

有什么方法可以使用 ImageSharp 从 .net core2 中的一些 jpeg 创建 gif?

我可以使用 Magick.Net 从一些 jpeg 创建一个 gif,但它在 Linux 上不起作用。

我想在 Ubuntu 14 上执行此操作。

编辑

我可以使用 ImageSharp 从 Jpegs 创建一个 Gif。这是我的源代码:

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

1 回答 1

11
  1. 加载你的两张图片
  2. 将第二张图像的第一帧(缩放后)作为 an 添加到第一张图像ImageFrame<T>Frames属性中。
  3. 将输出图像另存为 gif。

将图像保存为 gif 时会自动进行量化。目前将为每个帧生成一个单独的调色板。

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());
}
于 2018-02-05T00:06:58.493 回答