title: Set the content length for of a dynamical created image in ASP.NET
body: <p>I'm looking for easy way to set the content length of a dynamical created image in the Http Response.</p>
  
  <pre><code>Response.ContentType = "image/jpeg";
  Response.Clear();
  Response.BufferOutput = true; 
  ...
  Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
  ...
  bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
  Response.Flush();
  </code></pre>
  
  <p>Trying to do set the content length with</p>
  
  <pre><code>Response.AddHeader("Content-Length", Response.OutputStream.Length()) 
  </code></pre>
  
  <p>Gives unexpected results.</p>
  
  <p>Also I don't wish to copy the file into another stream (say MemoryStream) and copy it again to the output stream.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks.</p>