Monday, June 15, 2009

Vector or Image?

I'm learning that to take best advantage of the graphical model in WPF/Silverlight I need to shift much of the design work from bitmap based images to vector based graphics. This is especially true in Silverlight which has a much more limitted .NET class library, and no direct support for colorizing images.

In Solar Vengeance, I have a set of grayscale images that represent each StarShip type. When a game begins, SV dynamically generates colorized versions of the images for display. This was easy to do in WinForms and System.Drawing. I haven't found a reasonable solution to this in Silverlight. The WriteableBitmap class that's coming in Silverlight 3 might be a solution, but along the way I have found a better way.

The StarShip graphics for SV are very simple representations, and lend themselves well to vector based graphics. I can create custom classes in Silverlight that render the images using a combination of the simple graphics primitives that Silverlight offers, like Rectangle and Ellipse.

By creating a common StarShip visual base class, I can provide a single "Color" property that gets inherited to the customized rendering classes.

In the latest update of my demo app I render some StarShip types in a list box with a vector based version next to the image based. My work in progress is here ...

No comments:

Post a Comment