This method allows you to create a custom effects filter for raster images.

[Visual Basic]
Public Function CustomFilter(matrix(,) As Integer, div As Integer, level As Integer, red As Boolean, green As Boolean, blue As Boolean) As Boolean
[C#]
public bool CustomFilter(int[,] matrix, int div, int level, bool red, bool green, bool blue);

Parameters

matrix
     9x9 matrix (an array of 81 items ranging from 0 to 80)

div
     The division factor

level
     The bias factor (from 0 to 255, as this factor increases, the color becomes brighter)

red
     To process the red plane, set to True, otherwise set to False

green
     To process the green plane, set to True, otherwise set to False

blue
     To process the blue plane, set to True, otherwise set to False

Return Value

Returns True if successful. Returns False if unsuccessful.

Explanation

The CustomFilter method allows you to create a custom effects filter for raster images. An effects filter alters each pixel's color based on its current color and the colors of any neighboring pixels. (See the explanation of the filter matrix below.)

To execute the CustomFilter method, set the image handle of the image in the SourceImage property. The CustomFilter method supports 8-bit grayscale, 16, 24, and 32 bit images.

When processing a grayscale image the Red, Green and Blue parameter values are disabled.

Before executing the CustomFilter method, you must set the area on the image that will be affected. There are 4 ways to do this.

  1. To use a mask image, set the SelectMode property to EffectMask. Set the mask image handle in the SourceMask property
  2. To process the total image, set the SelectMode property to EffectAll
  3. To process the polygonal area on the image, set the SelectMode property to EffectPolygon. Set the appropriate values in the Point property
  4. To process an elliptical area on the image, set the SelectMode property to EffectEllipse. Select the ellipse by setting the appropriate values for the bounding rectangle in the Rect property

Note: When the SelectMode property is set to EffectPolygon or EffectEllipse, the values must be set in the Inside property.

If successful the resulting raster image data is set in the DestinationImage property.

The filter consists of an array of coefficients called a filter matrix. A filter processes an image on a pixel-by-pixel basis. Each pixel's color value is multiplied by the coefficient in the matrix center, and any pixels within the matrix are multiplied by the corresponding coefficients. The sum of the products becomes the target pixel's new value. To make the filter matrix, it is necessary to create an array containing 80 elements and set the appropriate coefficient values in the array elements. The formula used to calculate the target pixel's value is given below:


 

Where F is the output value of the target pixel, Pi is a pixel in the grid, and Ci is a coefficient in the matrix. Div is the division factor which allows you to achieve effects that would otherwise require decimal coefficients. Level is a bias factor. You use the bias to shift the value of each pixel by a fixed amount. As the bias factor increases, the resultant color is brighter. Bias adjustments are particularly useful for creating embossing effects.

Some sample matrix are given below:


 
 
 

See Also

Effect Class | Effect Members

The ImageKit.NET3 is created by Newtone Corporation