New ASP.NET Generated Image Control

The ASP.NET team released a new generated image control on to Codeplex today. You can download the bits here and read a very simple explanation of the control here.

The concept is simple: a handler that takes in a few parameters will render out an image. The control does what you would expect by instantiating the appropriate objects out of System.Drawing and renders the image to the screen. This handler may or may not be called by a generated image control in your ASPX markup, making it easy to implement into your HTML.

Using this control you’ll be able to render simple text as well as complex geometries and even graphs and charts.

Finding Chinks in the Armor

My first thought was to see how the control deals with transparency. While you can set the background color to transparent, I had a hard time getting text to look good with a transparent background. In image editing packages you can set a "matte" color which will step between transparency and the color of the text to preserve anti aliasing.I wasn't able to find a way to set a matte color. NOTE: There is the all-too-likely chance though that I missed something, so if you can point me in the right direction on this, please leave a comment.

Where’s the Evil?

Purists will undoubtedly criticize the use of this control to simply render text. Some say that you should never use an image to render text. While there is an excellent point in this position I think it’s important not to go overboard. There is nothing stopping you from by-passing the generated image control and accessing the handler directly to render the image. Using this approach you can simply define a background image in your style sheet and still render the appropriate text in HTML. (You can find many examples of this technique here)

Score on Day One

All in all I think they did a good job of making a control that is easy to use. In the future I would like to know more about how the handler deals with caching, effects performance and if there are any associated gotchas… but hey they just released it today, right? :)

 


If you are looking for a package to handle charts and graphs you may want to check out the NetAdvantage WebChart... I'm just sayin' ;)

 

kick it on DotNetKicks.com

Published Tuesday, August 19, 2008 1:56 PM by craigshoemaker
Filed under:

Comments

# re: New ASP.NET Generated Image Control

Tuesday, August 19, 2008 5:26 PM by Scott Galloway

Thanks Craig, it is an early release and we're certainly aware of the issues around scaling this type of approach...stay tuned!

# re: New ASP.NET Generated Image Control

Wednesday, August 20, 2008 2:26 AM by Satheesh

Does this control requires MVC framework to run? It says System.Web.Abstractions assembly could not be loaded.

# re: New ASP.NET Generated Image Control

Wednesday, August 20, 2008 8:39 AM by craigshoemaker

Satheesh:

If you have .NET 3.5/VS2008 SP1 installed it should work for you. The Abstractions DLL is updated with the SP1 install:

www.asp.net/.../Preview2.aspx

Craig

# re: New ASP.NET Generated Image Control

Friday, October 23, 2009 2:28 AM by suresh babu

this is really great... looking for these kind of things..

# re: New ASP.NET Generated Image Control

Sunday, December 6, 2009 5:54 AM by Samson

when i used the generatedimage control i am getting the below error

Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

can anyone help me.

# re: New ASP.NET Generated Image Control

Tuesday, December 8, 2009 3:58 PM by Nick Watt

I got the same error and had real problems sorting it. Are you using IIS7 on server 2008? What I did was add it to the GAC and it started working fine.