How to convert images in a folder to new formet

Posted by  Goti Bandu
Mvc  Mvc4 
 1367  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 />";

  1. Re: How to convert images in a folder to new formet

    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;

      Modified On Apr-09-2018 01:17:07 AM