简体   繁体   中英

asp .net out of memory problem

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

hi i am getting error while uploading pics

i get the error of

Out of memory. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Try switching from the built-in debugger or IISExpress to full-blown local IIS for testing. Often times there are some limitations (especially with IIS Express) that don't expose themselves in the same way with the different environments.

If that doesn't immediately resolve your problem, your best bet is to either use the memory profiling tools built into VS 2010, or to download and use a trial of the RedGate ANTS Profiler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM