0

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.

cs0815
  • 16,751
  • 45
  • 136
  • 299
  • I think you are probably looking for this link. http://stackoverflow.com/questions/186062/can-an-asp-net-mvc-controller-return-an-image – Muthu Dec 09 '11 at 12:44

3 Answers3

2

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

Community
  • 1
  • 1
Ashok Padmanabhan
  • 2,110
  • 1
  • 19
  • 36
1

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

dknaack
  • 60,192
  • 27
  • 155
  • 202
1

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" /> 
Ron Sijm
  • 8,490
  • 2
  • 31
  • 48