asp .net内存不足的问题

时间:2011-09-12 10:21:11

标签: c# asp.net

 private void GenerateThumbnails(double scaleFactor, string sourcePath,
 string targetPath) {
             int wi = Convert.ToInt32(Request.QueryString["dim2"]);
             int hi = Convert.ToInt32(Request.QueryString["dim1"]);
             using (var image =
 System.Drawing.Image.FromFile(sourcePath))
             {
                 var newWidth = (int)(wi);//(image.Width *
 scaleFactor);
                 var newHeight = (int)(hi);// (image.Height *
 scaleFactor);
                 var thumbnailImg = new Bitmap(newWidth, newHeight);
                 var thumbGraph = Graphics.FromImage(thumbnailImg);
                 thumbGraph.CompositingQuality =
 CompositingQuality.HighQuality;
                 thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                 thumbGraph.InterpolationMode =
 InterpolationMode.HighQualityBicubic;
                 var imageRectangle = new Rectangle(0, 0, newWidth,
newHeight);
                 thumbGraph.DrawImage(image, imageRectangle);
                 int getwal = newWidth - 108;
                 int gethi = newHeight - 30;
                 SolidBrush brush = new SolidBrush(Color.FromArgb(113,
 255, 255, 255));
                 thumbGraph.DrawString("myfile", new Font("Arial", 12,
 System.Drawing.FontStyle.Bold), brush, getwal,gethi);
                 thumbnailImg.Save(targetPath, image.RawFormat);
             } }

嗨我在上传图片时遇到错误

我得到错误

内存不足。描述:期间发生了未处理的异常  执行当前的Web请求。请查看堆栈  跟踪以获取有关错误及其来源的更多信息  代码。

Exception Details: System.OutOfMemoryException: Out of memory.

 Source Error: 


 Line 177:            thumbGraph.InterpolationMode =
 InterpolationMode.HighQualityBicubic; Line 178:            var
 imageRectangle = new Rectangle(0, 0, newWidth, newHeight); Line 179:  
 thumbGraph.DrawImage(image, imageRectangle); Line 180:           
 thumbnailImg.Save(targetPath, image.RawFormat);

1 个答案:

答案 0 :(得分:0)

尝试从内置调试器或IISExpress切换到成熟的本地IIS进行测试。通常情况下存在一些限制(特别是对于IIS Express),这些限制不会以不同的环境以相同的方式暴露自己。

如果这不能立即解决您的问题,最好的办法是使用VS 2010中内置的内存分析工具,或者下载并使用RedGate ANTS Profiler的试用版。