简体   繁体   English

如何获取要在MVC 2中显示的位图图像

[英]How do I get a bitmap image to show in MVC 2

I am pretty new to MVC 2 and would be grateful for any help. 我是MVC 2的新手,非常感谢任何帮助。

In my database I have a field for the thumbnail which is stored as a System.Drawing.BitMap. 在我的数据库中,我有一个缩略图字段,存储为System.Drawing.BitMap。

I have a partial view that needs to generate the image in the html. 我有部分视图需要在html中生成图像。

I have seen links to FileResult but this is the controller. 我见过FileResult的链接,但这是控制器。 With model binding how do I embed the image in the generated html page from a partial view? 使用模型绑定如何从部分视图中将图像嵌入到生成的html页面中?

Not sure if I need some "image" tag in my html or what format the data from the partial view must be in for it to show the thumbnail? 不知道我的html中是否需要一些“图像”标签,或者部分视图中的数据必须以什么格式显示缩略图?

JD JD

You need to have a controller action which returns a FileStreamResult and then use an <img> tag pointing to this controller action. 您需要有一个控制器操作,它返回一个FileStreamResult,然后使用指向此控制器操作的<img>标记。

public ActionResult Image(int id)
{
    byte[] imageData = GetImageFromDb(id);
    return File(imageData, "image/jpeg");
}

And then inside your view: 然后在你的视图中:

<img src="<%: Url.Action("image", new { id = Model.ImageId }) %>" alt="some image" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM