I’ve been wanting to build a sample that spotlights Silverlight 3’s new SaveFileDialog, but I wanted the sample to actually do something. So I built a Silverlight app that lets you load photos, remove red eyes, and save the edited photos back to disk in PNG format. Silverlight 3’s new WriteableBitmap class provides the pixel-addressable API needed to manipulate onscreen images, and, of course, SaveFileDialog makes it possible to write modified images to the local file system.
The red-eye removal algorithm that I used is a simple one, but it’s surprisingly effective. Here’s an old picture of my kids with some very obnoxious red eyes loaded into the app:
And here’s how the same picture looks with the red eyes removed:
To fix a red eye, you simply drag a selection rectangle around it with the left mouse button held down. Fix as many as you want and then click the Save button to display a SaveFileDialog.
It’s amazing how far Web apps have come in the last year or two; imagine trying to write an app like this before the advent of RIAs.
WriteableBitmap makes it relatively simple to generate or modify images in Silverlight 3, but one feature Silverlight still lacks is an image encoder. There’s nothing built into Silverlight, for example, to generate a JPG or PNG from a WriteableBitmap. To compensate, I used Joe Stegman’s PNG Encoder. Joe’s encoder works very well, but it outputs uncompressed images. Consequently, the image files you save to disk are typically much larger than the ones you loaded. In addition, Joe’s encoder supports a maximum image size of 2,047 x 2,047, so I display an error message if you try to load anything larger.