SecurityException when calling Graphics.DrawImage

后端 未结 1 1733
陌清茗
陌清茗 2021-01-17 04:22

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

相关标签:
1条回答
  • 2021-01-17 05:13

    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);
        }
    }
    
    0 讨论(0)
提交回复
热议问题