Image Generation is released to CodePlex


I’m really happy to announce that earlier this week we released a new feature called Image Generation to the ASP.NET CodePlex site. You can get a link directly to the page supporting this feature by clicking on: http://www.codeplex.com/aspnet/Wiki/View.aspx?title=WebForms&referringTitle=Home.

 

There was a feature that was in Beta 1 for Visual Studio 2005 (Whitbey) called DynamicImage that provided a control for generating images and an image service for serving them. This feature was sadly cut because some of the other parts of the framework it depended on were cut.

 

Image Generation is basically work to bring this type of feature back into the framework. Here are some of the highlights of what this new feature does:

 

New GeneratedImage ASP.NET control. This control is a derivative of asp:Image control that supports being hooked up to an Image Handler and passing parameters to it. If you put this control on a page and go into design mode it will have chrome attached to it that when clicked will automatically generate an ImageHandler and wire the control to the URL of the ImageHandler. Parameters such as the primary id and timestamp can be databound to the control and will automatically be passed to the handler.

 

ImageHandler which is an implementation of IHttpHandler that provides support for many image based things:

  • Transforms (resizing, watermarks, user defined transforms)
  • Client-side caching
  • Server side caching
  • Access to parameters passed from the GeneratedImage control
  • Provide simple mechanics for returning images

 

If you click to the site there are three samples of how to use GeneratedImage:

  • Simple Generated Image – this shows how you would create a simple bitmap and return it
  • Databased Images – shows how you would use this feature to display images that are stored in a database
  • Custom Image Transforms – shows how to write a custom image transform that adds a ASP.NET logo to an image

We are considering adding this feature in the next version of .NET and would love feedback. Please download and try and it out and let us know what you think!


Comments (8)

  1. Elijah Manor says:

    I’ve done my share of GDI+ generation… I think I’d like to do less of it rather than more 😉

    We have run into a lot of issues with performance, accessibility, and integration with 3rd party vendors.

    http://tinyurl.com/6ym4ab

  2. Mike says:

    Yes, add it please, no need to consider! One detail I have run into implementing this kind of thing (which I hope you guys will look into): most people do not specify the actual encoding for the image. I don’t mean the reponse type, but the actual way GDI will create the image.

    I ended up generating PNG’s (seems to be the default) without realising it and specifying jpeg as the content type for the response. All browsers displayed the image fine, which is great, but it hides the fact that my implementation was wrong.

    Just something to remember. Ideally, when transforming or working with existing images, this handler should take care to use the correct encoding (same as the original) so as not to turn a jpeg into a png.

    Thanks!

  3. Petr says:

    Will be fine if link to on-line demo is provided:-)

    I do something similar some time ago and I have problems with generating transparent gifs in medium trust environment – this helps me:

    http://codebetter.com/blogs/brendan.tompkins/archive/2007/06/14/gif-image-color-quantizer-now-with-safe-goodness.aspx

    P.

  4. yousaid says:

    Great tool. Include it in the next release. Writing your own GDI generation is very time consuming and most third party tools have issues working as advertised.

    Looks like many useful tools were cut from the Whitbey. Am I missing something, but if I recall correctly,  there was an RSS generation control also that was  cut? Am I right or wrong?

    Cheers,

    yousaid

  5. jstranger says:

    Definitely a lot of demand for something like this. But am having a few problems getting it to do exactly what I want. I need to be able to perform a series of transforms on an image supplied programmatically and maintain state. I have tried putting the image into a session variable and adding Implements IReadOnlySessionState but for some reason when I retrieve it in my image handler all properties are shown as ‘parameter is invalid’.

    Could do with a few more examples and documentation!

    Jon

  6. Mark Beatty says:

    I’ve tried out the GenerateImage control and it is certainly something that should be in the next version of .NET.  [Actually, I think that it should have been in 2.0]  However, I am finding it tricky to set the parameters programatically. For example, this works fine:

    <Parameters>

       <cc1:ImageParameter Name="ID" Value="1" /> </Parameters>

    But in the .ashx file this does NOT work:

    string qsID = HttpContext.Current.Request.QueryString["id"].ToString();

    parameters.Add("ID", qsID);

    Thus, I would be grateful for any info on how to set the NameValueCollection parameters.

    Thanks,

    Mark Beatty

  7. gkovacs says:

    Try this:

    imageObject.Parameters.Add(new Microsoft.Web.ImageParameter { Name = "ID", Value = qsID });