Reputation: 17388
I would like to create a jpeg on the fly given some data from a database. 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.
This should be fairly straight forward. Could someone please point me to some existing code?
Thanks.
Upvotes: 0
Views: 427
Reputation: 8738
There is a tutorial on msdn on How to: Encode and Decode a JPEG Image.
Doing that in MVC3 is pretty similar, you just need a action in your controller like this:
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" />
Upvotes: 1
Reputation: 60448
If you want this in pure mvc you can do this
Extending MVC: Returning an Image from a Controller Action
Another way is to create a HttpHandler that does that for you
HTTP Handlers for Images in ASP.NET
hope this helps
Upvotes: 1
Reputation: 2120
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
Scott Hansleman's post
Upvotes: 2