This post is about applying the same technique I presented for ASP.NET Web Forms, but this time for MVC.
We need to have an ActionResult that does the actual work of converting whatever we draw in the Graphics context into an image with an inline Data URI. Here’s a possible solution, where you only specify the dimensions of the image to be generated:
Now, we need to create an instance of this result and draw in it, in a controller’s action method:
As you can see, this provides a very convenient way to generate images on the fly. You just need to learn about the drawing methods in GDI+.