65.9K
CodeProject is changing. Read more.
Home

Using Dynamic Graphics in C#

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.33/5 (6 votes)

Feb 19, 2004

1 min read

viewsIcon

61871

downloadIcon

949

An article on the practical uses of dynamic graphics

Introduction

The dynamic creation of graphics within the .Net Framework is a powerful feature that can be adapted to a wide range of purposes. Here I have developed a demonstration that

  • a) generates graphics dynamically from text inputted by a user
  • b) mixes dynamic graphics with a static graphic to show you how flexible .Net graphic handling is.

The graphic routines lend themselves to any environment where a standard look and feel needs to be applied with a minimum of effort.

Using the code

The attached project file contains an ASPX file which has a handful of HTML controls allowing the user to specify two pieces of text that will be transformed into our XP style header bars. The code behind file inspects these controls and instantiates an instance of the CompleteImage Class. The CompleteImage class in turn instantiates instances of the HeaderImage inner class that are responsible for the nice anti aliased text bars you’ll see in the final image. The ComplteImage class is responsible for building a bitmap that combines the users text and heading bars and exposes the finished product via the CANVAS property.

/// Instantiating a CompleteImage object
CompleteImage ci = new CompleteImage (
  “header one”,”header two”,”test”);

/// Addi/// Adding a header to our CompleteImage object
d.DrawImage(((HeaderImage) new HeaderImage(
  this.headercolor,”text to display”)).IMAGE,0,0); 

Points of Interest

The HeaderImage class is overloaded. One of the constructors allows the developer to specify the color of the header bar they would like to create. Functionality like this can save a lot of time, traditionally a designer would have to create a new version of the graphic in a paint application and save it to the web server.

History

  • 16.01.04 Version 1.0 released