This artical introduces how to write code to feather an image with PhotoController. Firstly, please allow me to explain what feather operation is. You might have seen this operation in PhotoShop or Fireworks. Feathering an image is the process of taking out pixels from the edges of an image and allowing the pixels behind the image to "peek" through the image. The metaphor is intended to remind you of the feathers of a bird which allows light to peek around the feathers. PhotoController allows you to define any kind of the feather region, such as rectangle, ellipse, polygon, closed curves, and path.
Now suppose we want to feather the following image with a purple rectangle region.
We can use the following code:
1: IC.PhotoController.Controller pc = new IC.PhotoController.Controller("yellow_rose.jpg");
2: FeatherBuilder builder = new FeatherBuilder(360, 270); // by using the image size
3: builder.BackgroundColor = Color.Purple; // tell the builder to use purple
4: builder.BuildRectangleMask(new Rectangle(30,30, 330, 240)); // create a rectangle feather region
5: Image result = pc.Feather(builder);
6: pc.Dispose();
7: builder.Dispose();
You can see from the code above this operation is pretty straightforward. BuildXXXMask method is critical. It will notify the Builder to have such a region, so when calling the Controller.Feather method, it will be able to apply the effect.
Framing with Feather
Here is an interesting usage when combining Border and Feather, you can simulate a fancy framing effect. The trick is we can write a grey border to the image first, then apply the feather by using a tile bitmap behind. What happens is, we can see the grey border first, then gradually show the bitmap behind. The gradual change from the grey color to the tile bitmap simulate an engrave effect so it looks like a frame.
1: Controller pc = new Controller(pic.Image);
2: FeatherBuilder builder = new FeatherBuilder(pic.Image.Width, pic.Image.Height);
3:
4: // tell builder to use bitmap as background
5: builder.BackgroundStyle = FeatherBackgroundStyle.UseBitmap;
6:
7: string currentfolder = Path.GetDirectoryName(Application.ExecutablePath);
8: builder.LoadTileBitmap(currentfolder + "\\BackgroundTexture1.bmp");
9:
10: // set band to a small value.
11: // if this value is too large, the picture will be feathered too much
12: builder.Band = 10;
13:
14: // create a rectangle that is 25 smaller than picture
15: // the width 25 will be replaced by tile bitmap
16: Rectangle rect = new Rectangle(25, 25, pic.Image.Width - 50, pic.Image.Height - 50);
17: builder.BuildRectangleMask(rect);
18:
19: // we can draw a gray border that is slightly larger than the feather region, so we
20: // will feather the image with the grey edges
21: BorderBuilder borderBuilder = new BorderBuilder();
22: borderBuilder.Brush = new SolidBrush(Color.Gray);
23: borderBuilder.Length = 28;
24: pc.SetBorder(borderBuilder);
25:
26: pic.Image = pc.Feather(builder);
27: pc.Dispose();
28: builder.Dispose();
With the code above, we can generate the following result:
[Back to Top]