1
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);
} }
喜上載圖片ASP.NET的內存不足的問題
我得到的
錯誤內存不足。我收到錯誤。說明: 執行當前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);
GenerateThumbnails()與'上傳圖片'有什麼關係? –
等一下,這是一個asp.net應用程序,您正在從Image.FromFile文件加載圖像?您是否知道您正在從服務器的文件系統讀取文件,而不是客戶端?此外,你是否知道,爲了從服務器讀取它,你可能需要做Server.MapPath?這可能是也可能不是錯誤的原因。 – Icarus
好消息是,Image類對於任何事都抱怨OutOfMemory,所以它可能是別的。像錯誤的路徑或大小計算出錯。使用調試器。 –