在我的控制器中,我创建了一个从数据库返回图像的操作。图像存储为bytearrays,所以我将内容作为FileContentResult返回。获取指向FileContentResult返回文件的链接
在视图中,我链接到这个行动:
<img src="@Url.Action("GetImage", new { id=a.Id })"/>
控制器动作看起来像
public ActionResult GetImage(long id)
{
var article = SolrOperations.GetArticleById(id);
if (article != null && !string.IsNullOrEmpty(article.Image) && !string.IsNullOrEmpty(article.ImageType))
{
var imageBytes = Convert.FromBase64String(article.Image);
return new FileContentResult(imageBytes, article.ImageType);
}
return null;
}
这不会产生期望的行为(即使是显示的图像),因为我需要图像的完整链接,即:/getimage/id.jpg而不是/ getimage/id。原因是我想通过在图像src属性(fx src =“myimage.jpg?filter = greyscale”)中提供查询字符串来使用ImageProcessor.Web来进一步处理(并缓存)图像。
这是一个老问题,但你应该使用['IImageService'(http://imageprocessor.org/imageprocessor-web/extending/#iimageservice)实现从数据库返回的图像。 – 2017-02-02 05:46:15