This section will teach you how to create dynamic images that you can use in your ASP.NET applications. Graphics and imaging are an area that I have found most developers to be somewhat lacking in. I am not really sure why this is; probably because most developers end up creating database applications, or applications with complicated user interfaces. When I started programming in the early '80s, the user-interface elements that are so common today did not exist. So that meant that you had to draw your own objects.
With that said, though, you still need to ask yourself why you would want to create dynamic images for your ASP.NET applications. After all, we have the modern user-interface objects. And there is DHTML, which offers many of the graphical techniques that you might desire. But DHTML is not the panacea it is claimed to be. Different browsers respond in different ways, and even different browser versions respond in different ways. In fact, a good piece of DHTML code will not work at all on some browsers. I was sitting next to a friend of mine at the Authors' Summit that Microsoft invited us to in the summer of 2000. When speakers started talking about the GDI+ technology and what you could do with it in an ASP.NET, my friend turned to me and said, "Why would I need that? DHTML does everything they are talking about." Well, the fact is, DHTML doesn't do everything that GDI+ does, and GDI+ doesn't rely on a browser version to work correctly.
So what types of things could you do with dynamic images? Well, there are some marvelous answers to that question. You can create charts and graphs to display data that users might want to see, as I've done for this chapter's application. For instance, if you are tracking a certain stock, you can easily represent its movement with a graphical chart that is generated on demand. And this generated chart will reflect the current information about that particular stock, such as its current price, its PE (performance evaluation), and its high and low. This graphic representation gives users a much more pleasant experience than just seeing a bunch of numbers in some sort of table. People would almost always rather see something represented graphically than in a text-based table.
Besides applications that depict charts and graphs, you can envision a raft of scientific applications. These applications might show astronomical data in the form of charts, they might show star charts for the evening, they might show weather maps, or they might show some sort of engineering model. There is almost no end to what kinds of scientific and engineering applications you could create if you could dynamically generate images from a Web-based application.
Some of you at this moment are saying, "Well, I have been doing this for years. I have an ASP-based application that dynamically generates images." And I could say the same thing, because I have an application on www.ekidplace.com that allows users to create certificates online. The certificates are generated using some COM objects on the server end that takes the user's input and creates the resulting certificate image. I also have an interesting interactive application on the same Web site that lets users create graffiti-like images. These images are then dynamically rendered on the server side, saved to disk, and indexed in a database. The entire application is fairly complicated, but it illustrates that even without ASP.NET and GDI+, you can dynamically create images in a server-side ASP application. But to do both of those applications I just described took a lot of work. I had to do all the imaging myself, I had to write, test, and debug the COM objects, and then I had to work out a lot of details along the way. ASP.NET with its GDI+ components makes the entire process much easier. And that is what this chapter will talk about how to use these ASP.NET features to quickly and effectively create applications with dynamic images.