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);
} }
私はメモリ不足
のエラーが出るのアップロード中に、私はエラーを取得していますこんにちは。説明:現在の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に何かについて不平を言っていることです。だからそれはおそらく別のものです。間違ったパスやサイズ計算が間違っているように。デバッガを使用します。 –