Dynamically Generate an Image

Problem

You want to render dynamic graphics (perhaps to build the output for a chart or graph control).

Solution

Build the graphic using GDI+ and an in-memory Bitmap object, and then save it to the page output stream.

Discussion

You can draw dynamic graphics using the same GDI+ code in a Web application that you would use in a Windows application. The only difference is how you render the final graphic.

Dynamically generating an image imposes more of an overhead than using basic ASP.NET server controls. Therefore, these techniques are typically used only when you need to generate dynamic content. The following example creates the output for a pie chart based on the supplied data. The pie chart data is created as a series ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.