上传图片并修改其大小(C#)的方法

发表于:2007-06-17来源:作者:点击数: 标签:
上传图片并修改其大小 //thefile是一个File Field HTML 控件 thefile.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("temp.png")); MemoryStream MemStream=new MemoryStream(); System.Drawing.Image imgOutput =System.Drawing.Bitmap

   
  上传图片并修改其大小
  //thefile是一个File Field HTML 控件
  thefile.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("temp.png"));
  MemoryStream MemStream=new MemoryStream();

  System.Drawing.Image imgOutput =System.Drawing.Bitmap.FromFile(System.Web.HttpContext.Current.Server.MapPath("temp.png"));
  //修改成80×80大小
  System.Drawing.Image imgOutput2=imgOutput.GetThumbnailImage(80,80,null,IntPtr.Zero);
  imgOutput2.Save(System.Web.HttpContext.Current.Server.MapPath("image.png"), ImageFormat.Png);
  Response.Write(thefile.PostedFile.FileName);
  Response.Write("Len:"+MemStream.Length.ToString());
  imgOutput.Dispose();
  imgOutput2.Dispose();
  Response.Write("上传成功!");
  Response.Write(System.Web.HttpContext.Current.Server.MapPath("image.png"));

原文转自:http://www.ltesting.net