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.

1

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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" /> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.