Represents a filter used for the convolution treatments.
public class ConvolutionFilter: Filter
ObjectFilterConvolutionFilter
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.
// 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 );
// 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:");
Debug.WriteLine("\tBias:" +convolFil.Bias);
Debug.WriteLine("\tClamp:" +convolFil.Clamp);
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);
}
}
public class Form1 : System.Windows.Forms.Form
{
private MyControl control1= null;
public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
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);
}
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]
*/
Namespace System.Drawing.Filters Flash Library System.Windows.Forms.scl Flash Library Version 2.0.0.2118 Silverlight Library System.Windows.Forms.dll
| © 2003-2007 NETiKA Technologies. All rights reserved. |