10. June 2011 20:44by JP Hellemons
As you can read in the blogpost about access jpg’s through ftp with asp.net. I have explained there how I connected with FTP and retrieved images of the IP security camera. Now I have slightly modified the LINQ so that it downloads the latest 3 images and I would like to animate the transition between them. Now I know that I can use some fancy jQuery for image transitions, but I would like to merge the three images in a Gif.
Here is how I have accomplished it with Asp.Net C#
I have searched the web for a decent and free Gif library and found this post on CodeProject from 2005! (Epic!)
So I have downloaded the sources and had to compile the DLL myself. Don’t worry. I will upload the compiled version so that it saves you some time. Please note that my Visual Studio 2010 converted the sources from 2005 to .Net 4. So that might be a problem.
Here is my snippet for taking 3 images of the FTP source and adding them as frames to the gif.
var fis = fc.ListDirectoryDetail(dirLast.FullName + "/").GetFiles("jpg").AsEnumerable().Reverse().Take(3);
string gifName = Server.MapPath("~/tempwrite/" + foldername + ".gif");
AnimatedGifEncoder e = new AnimatedGifEncoder();
e.SetRepeat(0); //-1:no repeat,0:always repeat
int counter = 0;
foreach (FTPfileInfo fi in fis)
fc.Download(fi.FullName, Server.MapPath("~/tempwrite/" + foldername + counter + ".jpg"), true);
e.AddFrame(System.Drawing.Image.FromFile(Server.MapPath("~/tempwrite/" + foldername + counter + ".jpg")));
Credits for NGif go to gOODiDEA.Net