将文件夹中的图像转换为新格式

时间:2014-09-16 02:38:52

标签: asp.net asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp-classic

我正在尝试将文件夹中的一组图像转换为动画gif并面临错误

  

"无法访问已关闭的流。"

此外,显示图像中一定有错误。

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 个答案:

答案 0 :(得分:0)

您需要先将图像存储在驱动器上,然后将其路径提供给图像标记。

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;