CodeCarvings Piczard V1.2 Help
How To Apply More Than One filter
See Also Send Feedback
Piczard Fundamentals - Core > How To Apply More Than One filter

Glossary Item Box

Please see the Example A.102 - "Use multiple image filters".

The ImageProcessingFilterCollection is a class that allows to apply an unlimited number of ImageProcessingFilters, so that each filter is executed in chain one after the other.
The image generated by a filter is used as input by the following filter in the chain.
For this reason it's very important the order in which an ImageProcessingFilter is added to the collection.

In fact if, for example, you add a ResizeConstraint filter after a Watermark filter, then also the watermark will be resized.
Vice-versa, if you add a ResizeConstraint filter before a Watermark filter, then the watermark will not be resized.


The interesting thing is that the ImageProcessingFilterCollection class is itself an image processing filter (it inherits from ImageProcessingFilter).

In other words, when you instantiate a new ImageProcessingFilterCollection and you add some filters to it, in the fact you are creating a new "complex" filter that is composed by the sum of other sub-filters.

You can add any kind of filter to your ImageProcessingFilterCollection, even other collections of filters !
This means can you can easily build complex trees of filters.

Once you added filters to the collection, you can process an image by using one of the image processing methods inherited by the ImageProcessingFilter base class:

Please note that all the filter contained in the collection is applied only when one of the image processing method is invoked.


In the following example, the image is first resized (50% of the original size) and then a TextWatermark is applied

Copy Code
ImageProcessingFilterCollection myFilter = new ImageProcessingFilterCollection();
new ImageTransformation(50F));
new TextWatermark("My watermark"));
"Source.jpg", "Output.jpg");


Another interesting thing to know is that the sum operator of the ImageProcessingFilter class is overloaded.

The result of the sum of two (or more) ImageProcessingFilter objects is a new ImageProcessingFilterCollection.
Thus, the above example is equivalent to:


Copy Code
var myFilter = new ImageTransformation(50F) + new TextWatermark("My watermark");
"Source.jpg", "Output.jpg");

See Also

©2013 Sergio Turolla. All Rights Reserved.