2011-12-15 10 views
0

asp.net mvcがファイルストリームを提供するように間違った方法があります。これは次のようになります。mvcがファイルストリームを提供する実際の方法は何ですか?

public void SlideThumbnail(Guid id, int? width, int? height) 
    { 
     /*make the thumbnail code here*/ 

     using (Bitmap thumbnail = imageThumb.Generate(path)) 
     { 
      var msOutput = new MemoryStream(); 

      thumbnail.Save(msOutput, ImageFormat.Png); 
      Response.ContentType = "image/png"; 
      msOutput.WriteTo(Response.OutputStream); 
     } 
    } 

これはスーパーデュパーです。代わりにbase.File()を使用するようにコードを修正しようとしました。このように:

public ActionResult SlideThumbnail(Guid id, int? width, int? height) 
    { 
     /*make the thumbnail code here*/ 

     using (Bitmap thumbnail = imageThumb.Generate(path)) 
     { 
      var msOutput = new MemoryStream(); 

      thumbnail.Save(msOutput, ImageFormat.Png); 
      return base.File(msOutput, "image/png"); 
     } 
    } 

しかし、これは実際には何もしていないようです。 ?。私はこのMVCの方法を達成するかどのように私はすべてのエラーを得ることはありませんが、私もそう

:-(任意の画像を得ることはありません

+0

あなたはどのようなエラーが出るのですか? –

+0

エラーが返されません – quakkels

答えて

0

我々はそれを考え出した私は追加する必要:

thumbnail.Save(msOutput, ImageFormat.Png); 
msOutput.Seek(0, SeekOrigin.Begin); // <--- this line 
return base.File(msOutput, "image/png"); 

、我々はすべての良いです。

関連する問題