Knowledge Base > How to Use Image Filters
PhotoController 2.1
ContentsIndexHome
PreviousUpNext
Image Processing Filters in .NET

Since PhotoController V2.0, the Filter part is refactored, the previous Controller.Filter method is overloaded. You can call this method with either of the following two ways:

1. Controller.Filter ( IC.PhotoController.FilterStyle )

This method accepts an enumeration value, which defines a filter. It will create a Filter class with default parameter values automatically according to the specified FilterStyle. It is convenient to call a filter with default settings, and also handly for the filters without any parameter, such as GrayScaleFilter, InvertColorFilter, etc.

For example, the following code performs the sepia filter with a default value 21, which might be the best result for most images.

IC.PhotoController.Controller objpc = new Controller(img);

img = objpc.Filter(FilterStyle.Sepia);

The following code performs the grey filter, GreyFilter doesn't need any parameter, so it's just handy to call it with only two lines (of code).

IC.PhotoController.Controller objpc = new Controller(img);

img = objpc.Filter(FilterStyle.Grey);

2. Controller.Filter ( IC.PhotoController.Filter.BaseFilter )

This method accepts a filter class that is a descendant of BaseFilter. Besides it, PhotoController v2.0 also offers two abstract classes, BaseColorFilter and BaseOffsetFilter, which also inherit from BaseFilter.

BaseFilter provides a base set of functionality for filters. Users must override ApplyFilter method.

BaseColorFilter provides a base set of functionality for filters that are color transformations.
Users must override transformColor method.

BaseOffsetFilter provides a base set of functionality for filters that are geometric transformations.
User must override transform method.

Their relationship is as follows

Base Filters Relationship

To use this method, you can pass an object that inherits from any of those three Base filter classes.

For example, the following code shows how to call this method by passing an InvertColorFilter class

IC.PhotoController.Controller objpc = new Controller(img);

img = objpc.Filter(new InvertColorFilter());

Because InvertColorFilter doesn't need any parameter, it is convenient to pass the class directly to the Filter method. But when a filter class requires some parameters and if you don't want to use the default settings, you will have to do this step by step as follows

IC.PhotoController.Controller objpc = new Controller(img);

// create an EmbossFilter and specify the parameters

EmbossFilter filter = new EmbossFilter();

filter.Level = 3;

filter.Direction = 120;

 

// apply the filter algorithm

img = objpc.Filter(filter);

This code is calling the EmbossFilter and specifying the different values to parameters.

By inheriting from BaseFilter, you are able to customize a filter. Please read how to customize image filter tutorial.

Send comments about this topic.
Copyright (c) 2006-2007 @ ImageComponent.NET All rights reserved.