I\'m deploying an MVC3 app that stores images in a database. The requirement is to do a GET to retrieve the image from the database and then write the image into the respon
Well, it turns out I was over complicating this. I found this good post that explained why I couldn't just save the bitmap from the database to the output stream.
That led me to try to eliminate the GDI+ call. I ended up with this that works beautifully (_imageBitmap has been pulled from the db):
public override void ExecuteResult(ControllerContext context)
{
using (Bitmap bitmap = new Bitmap(_imageBitmap))
{
context.HttpContext.Response.ContentType = "image/jpg";
bitmap.Save(context.HttpContext.Response.OutputStream, ImageFormat.Jpeg);
}
}