HOW TO CONVERT IMAGES IN A FOLDER TO NEW FORMET

Goti Bandu

Total Post:119

Points:835
Posted by  Goti Bandu
Mvc  Mvc4 
 1003  View(s)
Ratings:
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();
 
                memoryStream.SetLength(0); 
 
    }
    binaryWriter.Close();
    System.Drawing.Image streamGIF = System.Drawing.Image.FromStream(stream);
   Label1.Text += "<img src=" + streamGIF + " /><br />";
}

  1. Jeet Verma

    Post:110

    Points:776
    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);          
    binaryWriter.Close();
    img1.ImageUrl = imageName;

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!