Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net内存不足问题_C#_Asp.net - Fatal编程技术网

C# asp.net内存不足问题

C# asp.net内存不足问题,c#,asp.net,C#,Asp.net,嗨,我上传图片时出错 我得到的错误是 内存不足。描述:过程中发生未处理的异常 当前web请求的执行。请检查堆栈 跟踪以获取有关错误及其来源的更多信息 密码 private void GenerateThumbnails(double scaleFactor, string sourcePath, string targetPath) { int wi = Convert.ToInt32(Request.QueryString["dim2"]);

嗨,我上传图片时出错

我得到的错误是

内存不足。描述:过程中发生未处理的异常 当前web请求的执行。请检查堆栈 跟踪以获取有关错误及其来源的更多信息 密码

 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);
             } }

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


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

GenerateThumbnails()与“上传图片时”有什么关系?等一下,这是一个asp.net应用程序,您正在通过image.FromFile从文件加载图像?您是否知道您正在从服务器的文件系统而不是客户端的文件系统读取文件?此外,您是否知道,为了从服务器读取它,您可能需要执行server.MapPath?这可能是错误的原因,也可能不是。好消息是,Image类会因为任何事情向OutOfMemory抱怨,所以可能是其他原因。比如一条错误的路径或者一个尺寸计算出错。使用调试器。这里的映像维度是什么,可能是它们太大并导致内存溢出
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);