1

I'm creating ImageButtons on an asp.net website. Sometimes, however, an image doesn't exist for the given text and in those cases, rather than display a 'broken image', I want to simply convert the string to an image and display that.

I've seen how to create a Bitmap/Image using C# and .NET from a text string, however, I'm not sure how to utilize this for an asp.net project. The ImageButton requires an ImageUrl...so what can I do when I'm trying to dynamically create the images? Is there a way to create them and save them someplace that I can then point to or a way to create and show the images that doesn't require their being saved?

Any tips on how this could be achieved would be very much appreciated. Thanks!

JToland
  • 3,630
  • 12
  • 49
  • 70

3 Answers3

0

Certainly possible.

Dynamically Generating and Caching Images in ASP.NET with the GeneratedImage Control

Adam
  • 16,089
  • 6
  • 66
  • 109
  • That certainly looks like it'd solve my problem. Having never used VB, I'm a bit scared, but I'll read through the page and see if I can get something similar going with C#. – JToland Jan 29 '12 at 06:36
  • VB to C# is fairly straight forward. I used to be a VB.NET developer for 6 years then have been c# for 4 years. (much prefer c#). Tips: semi colon and everything is in reverse. Otherwise just google VB to C# translator. They are are heaps out there. – Adam Jan 29 '12 at 06:39
0

Try using a LinkButton instead. You can use File.Exists to see if the file exists, you may have to use VirtualPathUtility.ToAppRelative if you need to find the applications path to that file. If the file does not exist, you can set the LinkButtons value to just the name of the textual representation, otherwise you can put an image tag (hopefully with its alt attribute set).

Matthew
  • 24,703
  • 9
  • 76
  • 110
0

It's not generally considered good practice, but you could easily add a reference to Windows Forms and use GDI+. I've done this many times. Here's a link:

http://www.codeproject.com/Articles/1827/Web-Graphics-On-The-Fly-in-ASP-NET

Pedery
  • 3,632
  • 1
  • 27
  • 39