2011-09-12 11 views
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); 
+1

GenerateThumbnails()は「写真をアップロード中」と何が関係していますか? –

+1

少し待ってください。これはasp.netアプリケーションで、Image.FromFileを実行しているファイルからイメージをロードしていますか?クライアントのファイルシステムではなく、サーバーのファイルシステムからファイルを読み取っていることをご存知ですか?さらに、サーバーからそれを読み取るには、おそらくServer.MapPathを実行する必要があることに気づいていますか?それがエラーの原因である場合とそうでない場合があります。 – Icarus

+2

良いニュースは、ImageクラスがOutOfMemoryに何かについて不平を言っていることです。だからそれはおそらく別のものです。間違ったパスやサイズ計算が間違っているように。デバッガを使用します。 –

答えて

0

組み込みのデバッガまたはIISExpressから、本格的なローカルIISに切り替えてテストしてみてください。多くの場合、さまざまな環境で同じ方法で自分自身を公開しない(特にIIS Expressの場合)いくつかの制限があります。

これで問題がすぐに解決されない場合は、VS 2010に組み込まれているメモリプロファイリングツールを使用するか、RedGate ANTS Profilerの試用版をダウンロードして使用するのが最善の方法です。