string filename=Request.QueryString["filename"];
Bitmap bmpOld= new Bitmap(Server.MapPath("images/" + filename));  //计算缩小比例
double d1;
if (bmpOld.Height>bmpOld.Width)
d1=(double)(MaxLength/(double)bmpOld.Width);
else
d1=(double)(MaxLength/(double)bmpOld.Height); //产生缩图
Bitmap bmpThumb= new Bitmap(bmpOld,(int)(bmpOld.Width*d1),(int)(bmpOld.Height*d1)); // 清除缓冲 
Response.Clear();
//生成图片
bmpThumb.Save(Response.OutputStream, ImageFormat.Jpeg);
Response.End();
//释放资源
bmpThumb.Dispose();
bmpOld.Dispose();

解决方案 »

  1.   

    以上代码放在一个新的aspx文件里,如pic.aspx<img src=pic.aspx?filename=1.jpg>
      

  2.   

    this.ShowImage.ImageUrl=this.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["UserUploadFile"]+dr["UserPicture"].ToString());
    Bitmap bmp= new Bitmap(this.Server.MapPath(System.Configuration.ConfigurationSettings.AppSettings["UserUploadFile"]+dr["UserPicture"].ToString());
    this.ShowImage.Width=bmp.Height;
    this.ShowImage.Height=bmp.Width;
    if(System.Int32.Parse(this.ShowImage.Width.Value.ToString())>450)
    {
    this.ShowImage.Width=450;
    this.ShowImage.Height=(System.Int32.Parse(this.ShowImage.Height.Value.ToString())/System.Int32.Parse(this.ShowImage.Width.Value.ToString()))*450;
    }
      

  3.   

    设置一个css文件定义固定的高度和宽度应用在asp:image控件
      

  4.   

    Bitmap bmpOld= new Bitmap(Server.MapPath("images/" + filename)); 就是读的硬盘上的一个文件