GOA - System.Drawing.Filters.ConvolutionFilter

ConvolutionFilter Class


Represents a filter used for the convolution treatments.

Definition

public class ConvolutionFilter: Filter

Members Table

MethodDescription
CloneCreates a shallow copy of the current Filter. (Inherited from Filter)
ConvolutionFilterInitializes a new instance of ConvolutionFilter.
CopyMatrixCopies the ConvolutionMatrix of the ConvolutionFilter to another ConvolutionMatrix.
EqualsOverloaded. Compares two objects to determine if they are equal. (Inherited from Object)
GetHashCodeServes as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object)
GetTypeGets the Type of the current instance. (Inherited from Object)
ReferenceEqualsDetermines whether the specified Object instances are the same instance. (Inherited from Object)
SetMatrixSets a specified ConvolutionMatrix to the current ConvolutionFilter.
ToStringReturns a String that represents the current Object. (Inherited from Object)
PropertyDescription
BiasGets or sets the Bias property of the ConvolutionFilter.
ClampGets or sets a value indicating whether the image on which convolution is applied should be clamped.
DivisorGets or sets the divisor property of the ConvolutionFilter.
PreserveAlphaGets or sets a value indicating whether the Alpha channel should be preserved during the convolution.
SubstituteColorGets or sets the substitute Color for the pixels out of the image on which the convolution is applied on.

Inheritance Hierarchy

Object
Filter
ConvolutionFilter

Remarks

The Convolution is a method used in the image processing.

The Convolution method is a treatment of a matrix to one other; the first one is the image to be treated, the second one is the filter also known under the name of "kernel".

The Convolution method acts on each pixels of the image; it replaces each pixel with a weighted sum of itself and nearby pixels.

Examples

// This sample shows how to create an AsyncImage class and how to apply a ConvolutionFilter on it.

 

using System;

using System.Drawing;

using System.Diagnostics;

using System.Windows.Forms;

using System.Drawing.Filters;

 

public class MyControl : System.Windows.Forms.Control

{

     AsyncImage myAsyncImage;

 

     public MyControl() {}

 

     protected override void OnCreateControl()

     {

          Visual v= this.Visual;

 

          string url= "http://www.netikatech.com/demos/resources/image.aspx?index=1";

 

          // Creates a new instance of the AsyncImage.

          this.myAsyncImage = new AsyncImage(v, 30, 20 );

          this.myAsyncImage.Load(url );

 

          // Creates a new ConvolutionMatrix.

          ConvolutionMatrix convolMat = new ConvolutionMatrix(3,3);

 

          // Sets some elements of the ConvolutionMatrix.

          convolMat[0]=-2;

          convolMat[1]=-1;

          convolMat[2]=0;

          convolMat[3]=-1;

          convolMat[4]=1;

          convolMat[5]=1;

          convolMat[6]=0;

 

          // Uses the number of the row and column of the ConvolutionMatrix.

          convolMat[2,1]=1;

          convolMat[2,2]=2;

 

          // Displays the content of the ConvolutionMatrix.

          Debug.WriteLine("\nConvolution matrix:" +convolMat.ToString());

 

          // Creates a new ConvolutionFilter.

          ConvolutionFilter convolFil = new ConvolutionFilter();

 

          // Sets the ConvolutionMatrix to the ConvolutionFilter.

          convolFil.SetMatrix(convolMat);

 

          // Gets, sets and Displays some properties of the ConvolutionFilter.

          Debug.WriteLine("\nProperties of the ConvolutionFilter:");

 

          convolFil.Bias=50;

          Debug.WriteLine("\tBias:" +convolFil.Bias);

 

          convolFil.Clamp=false;

          Debug.WriteLine("\tClamp:" +convolFil.Clamp);

 

          convolFil.Divisor=2;

          Debug.WriteLine("\tDivisor:" +convolFil.Divisor);

 

          Debug.WriteLine("\tPreserveAlpha:" +convolFil.PreserveAlpha);

 

          convolFil.SubstituteColor= System.Drawing.Color.FromArgb(0, 255, 0, 0);

          Debug.WriteLine("\tSubstituteColor:" +convolFil.SubstituteColor);

 

          // Applies the ConvolutionFilter to the AsyncImage.

          this.myAsyncImage.ApplyFilter(convolFil);

 

          base.OnCreateControl();

     }

}

 

public class Form1 : System.Windows.Forms.Form

{

     private MyControl control1= null;

 

     public Form1()

     {

          InitializeComponent();

     }

 

     private void InitializeComponent()

     {

          this.SuspendLayout();

          this.control1= new MyControl();

          this.control1.Location= new System.Drawing.Point(10,10);

          this.control1.Size= new Size(Application.Width-10,Application.Height-10);

          this.Controls.Add(this.control1);

          this.ResumeLayout(false);

     }

 

     static void Main()

     {

          Application.Run( new Form1() );

     }

}

 

/*

The output of the sample:

 

Convolution matrix:[-2,-1,0,-1,1,1,0,1,2]

 

Properties of the ConvolutionFilter:

     Bias:50

     Clamp:False

     Divisor:2

     PreserveAlpha:True

     SubstituteColor:Color [R=255,G=0,B=0,A=0]

 

*/

Class Information

NamespaceSystem.Drawing.Filters
Flash LibrarySystem.Windows.Forms.scl
Flash Library Version2.0.0.2118
Silverlight LibrarySystem.Windows.Forms.dll



© 2003-2007 NETiKA Technologies. All rights reserved.