WebForm下载图片
WEBFORM下载图片
Download picture:
//Loading the picture file into the Image object System.Drawing.Image img=System.Drawing.Image.FromFile(
)
//The establishment of binary stream
MemoryStream ms=new MemoryStream();
//According the image file suffix name , write the file into binary stream switch ()
{
case "gif":
ContentType = "image/gif";
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
break;
case "jpg":
ContentType = "image/jpeg";
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
………
}
//Set the output format
Response.AddHeader("Content-disposition", "attachment;filename=" + )
//Set the format of data
Response.ContentType = ContentType;
//Set the encoding of data
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); //Output data in binary mode
WEBFORM下载图片
Response.BinaryWrite(ms.ToArray());
//Dispose the object used
img.Dispose();
ms.Dispose();
Response.End();