I'm trying to generate a 60 seconds gif representing a countdown timer.
Generating the frames is done using the following code:
Code: Select all
for (int i = 0; i < numberOfFrames; ++i)
{
DateTime dt = processingDateTime.AddSeconds(i);
MagickImage magickImage = new MagickImage(frameGenerator.Generate(dt))
{
AnimationDelay = 100
};
/* handle transparency if needed*/
if (this.contentDefinitionCountdown.TransparentBackground)
{
magickImage.SetAttribute("dispose", "background");
magickImage.Transparent(frameGenerator.TransparentColor);
}
yield return magickImage;
}
Code: Select all
using (MagickImageCollection collection = new MagickImageCollection())
{
collection.AddRange(this.GenerateFrames(processingDateTime, numberOfFrames));
collection.Coalesce();
result = collection.ToByteArray(MagickFormat.Gif);
}
Now the issue:
When using no background in my frames, the frame size is rather small (about 420 x 30 pixels) and the generation of the gif takes about 3 seconds which is not very fast but acceptable in our case. (If anyone has suggestion to speed up this process, do not hesitate to comment)
When using a background in the frames, the countdown text is rendered upon that background and the frames size is (800 x 600). In this case the generation of the animated gif takes about 15 seconds, which is not acceptable for our use case.
Now, as far as we can see there might be 2 solutions to this:
- Speed up the generation of the animated gif in some way
- Generate the animated gif without the background and somehow merge the resulting gif with the background image afterwards.
Can we do something to speed up the gif generation?
Is it possible to generate a small gif and afterwards combine it with the background image?
Regards,
Erwin Cuppens