【发布时间】:2019-06-27 09:29:45
【问题描述】:
谁能告诉我为什么这会生成一个只有黑色的动画 gif?
代码还输出每个在内存中生成的 gif 以表明它们是不同的
public static void Test()
{
Image<Rgba32> img = null;
Image<Rgba32> gif = null;
TextGraphicsOptions textGraphicsOptions = new TextGraphicsOptions(true);
SolidBrush<Rgba32> brushYellow = new SolidBrush<Rgba32>(Rgba32.Yellow);
FontCollection fonts = new FontCollection();
fonts.Install(fontLocation);
Font font = fonts.CreateFont("Liberation Mono", PngFontHeight, FontStyle.Regular);
gif = new Image<Rgba32>(400, 400);
for (int i = 0; i < 10;++i)
{
img = new Image<Rgba32>(400, 400);
img.Mutate(x => x.Fill(Rgba32.Black));
img.Mutate(x => x.DrawText(textGraphicsOptions, i.ToString(), font, brushYellow, new PointF(1,1)));
gif.Frames.AddFrame(img.Frames[0]);
using (FileStream fs = File.Create(Path.Join(Program.workingDirectory, string.Format("Test-{0}.gif", i))))
{
img.SaveAsGif(fs);
}
img.Dispose();
}
using (FileStream fs = File.Create(Path.Join(Program.workingDirectory, "Test.gif")))
{
gif.SaveAsGif(fs);
}
}
如果我将其编码为加载每个 individual physical file using this code,它会按预期制作动画 gif。
我只想在内存中创建动画 gif。
【问题讨论】:
-
从您的简短描述中,尚不清楚预期结果与实际结果是什么。
Test.gif只是一个黑框吗?这 10 个Test-{0}.gif文件是“个人 gif”吗?如果是,它们有何“不同”? -
@BACON 我更新了标题和描述
标签: c# .net-core animated-gif imagesharp