Home > DeveloperSection > Forums > How to convert images in a folder to new formet
Goti Bandu

Total Post:119

Posted on    February-05-2015 10:28 PM

 ASP.Net Mvc  Mvc4 

 1 Reply(s)
 793  View(s)
Rate this:

I am trying to convert a group of images in a folder to animated gif and facing error "Cannot access a closed Stream.".Also there must be error in display image as lable.. protected void Button1_Click(object sender, EventArgs e) {

    //Variable declaration

    MemoryStream memoryStream;



    binaryWriter = new BinaryWriter(stream);



   int numFiles = fileEntries.Length;

    for (int picCount = 0; picCount < numFiles; picCount++)


        image = System.Drawing.Image.FromFile(fileEntries[picCount]);


         image.Save(memoryStream, ImageFormat.Gif);

                buf1 = memoryStream.ToArray();







    System.Drawing.Image streamGIF = System.Drawing.Image.FromStream(stream);

   Label1.Text += "<img src=" + streamGIF + " /><br />";


Jeet Verma
Jeet Verma

Total Post:110

Posted on    February-05-2015 10:54 PM

You need to store the image first on drive and then give its path to image tag.

System.Drawing.Image streamGIF = System.Drawing.Image.FromStream(stream);

string imageName = "~/Images/test.gif";

string savePath = Server.MapPath(@"Images\test.gif");      

streamGIF.Save(savePath, System.Drawing.Imaging.ImageFormat.Gif);          


img1.ImageUrl = imageName;

Don't want to miss updates? Please click the below button!

Follow MindStick