2012-08-13 177 views
0

我用multi file upload在ASP.Net中上傳文件沒有問題。但現在我要像創建縮略圖添加更多的功能,同時在下面上傳是我的代碼:多文件上傳問題

try 
     { 
      string _path = "~/photos/realimg/"; 
      string _thumPath = "~/photos/thumbimg/"; 
      // Get the HttpFileCollection 
      HttpFileCollection hfc = Request.Files; 
      for (int i = 0; i < hfc.Count; i++) 
      { 
       HttpPostedFile hpf = hfc[i]; 
       if (hpf.ContentLength > 0) 
       { 
        _path += System.IO.Path.GetFileName(hpf.FileName); 
        _thumPath += System.IO.Path.GetFileName(hpf.FileName.Insert(0, "thumb_")); 
        hpf.SaveAs(Server.MapPath(_path)); 
        SavePicPath(_path); 
        System.Drawing.Image realImg = System.Drawing.Image.FromFile(Server.MapPath(_path)); 

        Int32 rH = realImg.Height; 
        Int32 rW = realImg.Width; 

        Int32 fW = 170; 
        Int32 fH = (Int32)Math.Floor((double)rH * (fW/rW)); 
        System.Drawing.Image thumbimg = realImg.GetThumbnailImage(fW, fH, null, IntPtr.Zero); 

        thumbimg.Save(Server.MapPath(_thumPath)); 
        SavePicPath(_thumPath); 

       } 
      } 
     } 
     catch 
     { 
     } 

每當它進入GetThumbnailImage我得到一個錯誤「內存不足」取悅任何修正或我在做什麼錯

+0

將int值更改爲(float或double) – MMK 2012-08-13 12:42:32

+0

@MMK感謝它的工作!但請說明它背後的祕密是什麼? – 2012-08-13 13:46:35

+1

檢查我的答案 – MMK 2012-08-13 13:55:49

回答

1

將int值更改爲(float或double)。我認爲在這裏fw/rw返回int值比float或double值。