[英]asp.net mvc controller method that returns jpeg given parameter
I would like to create a jpeg on the fly given some data from a database. 我想根据数据库中的一些数据即时创建一个jpeg。 The data is an array containing values which should be translated into a colour. 数据是一个数组,其中包含应转换为颜色的值。
A asp.net mvc controller method should return a jpeg on the fly given one parameter. 给定一个参数,asp.net mvc控制器方法应即时返回jpeg。
This should be fairly straight forward. 这应该是相当简单的。 Could someone please point me to some existing code? 有人可以指出一些现有代码吗?
Thanks. 谢谢。
Here are a couple of possible options that may help you get started: I think you will porbably need an handler and then call the handler from your controller. 这里有一些可能的选项可以帮助您入门:我认为您可能需要一个处理程序,然后从您的控制器调用该处理程序。
SO POst 这样
Bob Cravens post 鲍勃·克雷文斯(Bob Cravens)发布
Scott Hansleman's post 斯科特·汉斯勒曼(Scott Hansleman)的帖子
If you want this in pure mvc you can do this 如果您想在纯MVC中使用此功能,则可以执行此操作
Extending MVC: Returning an Image from a Controller Action 扩展MVC:从控制器操作返回图像
Another way is to create a HttpHandler that does that for you 另一种方法是创建一个为您执行此操作的HttpHandler
HTTP Handlers for Images in ASP.NET ASP.NET中图像的HTTP处理程序
hope this helps 希望这可以帮助
There is a tutorial on msdn on How to: Encode and Decode a JPEG Image . 在msdn上有一个有关如何:对JPEG图像进行编码和解码的教程。
Doing that in MVC3 is pretty similar, you just need a action in your controller like this: 在MVC3中执行此操作非常相似,您只需要在控制器中执行以下操作即可:
public class YourController : Controller
{
[HttpGet]
public ImageResult GetImage(int whatever)
{
stream imageStream = yourJpgFactory.GetImage(whatever)
return (imageStream)
}
}
and in your view 在你看来
<img src="YourController/GetImage?whatever=42" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.