Creating gif from two or more than two image #1206
-
public MagickImageCollection CreateGif(FileStreamResult defectiveImage, FileStreamResult gifSecondImage, int gifTime)
{
/*System.IO.MemoryStream gif = new System.IO.MemoryStream();
GifEncoder encode = new GifEncoder(gif);
encode.FrameDelay = TimeSpan.FromMilliseconds(gifTime);
encode.AddFrame(Image.FromStream(defectiveImage.FileStream));
encode.AddFrame(Image.FromStream(gifSecondImage.FileStream));
return gif;*/
defectiveImage.FileStream.Position = 0;
MagickImage image1= new MagickImage(defectiveImage.FileStream);
image1.Depth = 1;
gifSecondImage.FileStream.Position = 0;
MagickImage image2 = new MagickImage(gifSecondImage.FileStream);
image2.Depth = 1;
MagickImageCollection gif = new MagickImageCollection();
try
{
gif.Add(image1);
gif[0].AnimationDelay = 100;
gif.Add(image2);
gif[1].AnimationDelay = 100;
gif[1].Flip();
/*gif.Optimize();*/
return gif;
}
catch(Exception ex)
{
System.Console.WriteLine("Erro while creatng GIF: {0}", ex);
throw;
}
} The gif I get Is just a static image only. According to code the gif should have two image blinking at interval of 1 second |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 4 replies
-
Can you share the output image and which of the two images are you seeing? And the animation delay that you have now is |
Beta Was this translation helpful? Give feedback.
-
What could be the possible reason for this? |
Beta Was this translation helpful? Give feedback.
-
How are you calling |
Beta Was this translation helpful? Give feedback.
-
gif.write() is working fine but I do not have to write it on disk. I have to return it like this - I have other imges/gif and I am putting all in zip file. So I do not have to write on disk By the way, Thank You so much for you help |
Beta Was this translation helpful? Give feedback.
-
Earlier I used different library to create GIF. This was working fine for both GIF and image. |
Beta Was this translation helpful? Give feedback.
-
You should do |
Beta Was this translation helpful? Give feedback.
-
Thank You very much. It works for me. |
Beta Was this translation helpful? Give feedback.
You should do
gif.ToByteArray(MagickFormat.Gif)
instead.