title: Issue returning images over web api
body: <p>I am having a weird issue returning an image via web api, I do this in several places in my application without fail but this one is causing me issues, any help would be greatly appreciates.</p>
  
  <p>This works</p>
  
  <pre><code>  Bitmap bitmap = getImage();
          MemoryStream bitmapStream = new MemoryStream();
          bitmap.Save("C:\\test.png", System.Drawing.Imaging.ImageFormat.Png);
  
          if (bitmap != null)
          {
              if (Request.Headers.IfModifiedSince.HasValue)
              {
                  // The file has not been modified since the browser cached it.
                  return new HttpResponseMessage(HttpStatusCode.NotModified);
              }
              HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
              response.Content = new StreamContent(new FileStream("C:\\test.png", FileMode.Open));
              response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
              return response;
          }
          else
          {
              return new HttpResponseMessage(HttpStatusCode.NotFound);
          }
  </code></pre>
  
  <p>while this does not</p>
  
  <pre><code> Bitmap bitmap = getImage();
          MemoryStream bitmapStream = new MemoryStream();
          bitmap.Save(bitmapStream, System.Drawing.Imaging.ImageFormat.Png);
  
          if (bitmap != null)
          {
              if (Request.Headers.IfModifiedSince.HasValue)
              {
                  // The file has not been modified since the browser cached it.
                  return new HttpResponseMessage(HttpStatusCode.NotModified);
              }
              HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
              response.Content = new StreamContent(bitmapStream);
              response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
              return response;
          }
          else
          {
              return new HttpResponseMessage(HttpStatusCode.NotFound);
          }
  </code></pre>
  
  <p>I really need to do this in memory and not save a temp file to drive, but for some reason when I do it in memory the result is an empty file 0 bytes, I do try to set the content length manually but then the file doesnt download at all.</p>