webapi 直接输出图片

HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(ms.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
return result ; 

网上的代码基本上都是这样的 但是api的请求结果是Json

{"Version":{"Major":1,"Minor":1,"Build":-1,"Revision":-1,"MajorRevision":-1,"MinorRevision":-1},"Content":{"Headers":[{"Key":"Content-Type","Value":["image/jpg"]}]},"StatusCode":200,"ReasonPhrase":"OK","Headers":[],"RequestMessage":null,"IsSuccessStatusCode":true}

最终结果,输入图片 使用IAcitonResult ,返回子类FileContentResult,直接输出图片

public IActionResult GetQr(string str)
{
    var img = LIB.QR.GetQrCode(str);
    MemoryStream ms = new MemoryStream();
    img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
    return new FileContentResult(ms.ToArray(), "image/png");
}