首页 > 代码库 > MVC4 WebAPI中如何返回一张图片

MVC4 WebAPI中如何返回一张图片

    public HttpResponseMessage Get(string imageName, int width, int height)    {        Image img = GetImage(imageName, width, height);        MemoryStream ms = new MemoryStream();        img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);        HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);        result.Content = new ByteArrayContent(ms.ToArray());        result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");        return result;    }

MVC4 WebAPI中如何返回一张图片?

MVC4 WebAPI中如何返回一张图片