0

我使用多文件上传在 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 时,我都会收到“内存不足”错误,请更正或我做错了什么

4

1 回答 1

1

将 int 值更改为(浮点或双精度)。我认为这里fw/rw返回 int 值而不是 float 或 double 值。

于 2012-08-13T13:55:41.407 回答