Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > ConvolutionFilter (flash.filters.ConvolutionFilter) > ConvolutionFilter constructor | |||
public ConvolutionFilter(matrixX:Number, matrixY:Number, matrix:Array, [divisor:Number], [bias:Number], [preserveAlpha:Boolean], [clamp:Boolean], [color:Number], [alpha:Number])
Initializes a ConvolutionFilter instance with the specified parameters.
Availability: ActionScript 1.0; Flash Player 8
matrixX:Number - The x dimension of the matrix (the number of columns in the matrix). The default value is 0.
matrixY:Number - The y dimension of the matrix (the number of rows in the matrix). The default value is 0.
matrix:Array - The array of values used for matrix transformation; returns a copy. The number of items in the array must equal matrixX*matrixY.
divisor:Number [optional] - The divisor used during matrix transformation. The default value is 1. A divisor that is the sum of all the matrix values evens out the overall color intensity of the result. A value of 0 is ignored and the default is used instead.
bias:Number [optional] - The bias to add to the result of the matrix transformation. The default value is 0.
preserveAlpha:Boolean [optional] - A value of false indicates that the convolution applies to all channels, including the alpha channel. A value of true indicates that the convolution applies only to the color channels. The default value is true.
clamp:Boolean [optional] - For pixels that are off the source image, a value of true indicates that the input image is extended along each of its borders as necessary by duplicating the color values at the given edge of the input image. A value of false indicates that another color should be used, as specified in the color and alpha properties. The default is true.
color:Number [optional] - The hexadecimal color to substitute for pixels that are off the source image.
alpha:Number [optional] - The alpha of the substitute color.
The following code creates a 3 x 3 convolution filter with a divisor of 9. The filter would make an image appear blurred:
var myArray:Array = [1, 1, 1, 1, 1, 1, 1, 1, 1];
var myFilter:ConvolutionFilter = new flash.filters.ConvolutionFilter (3, 3, myArray, 9);
The following example creates a ConvolutionFilter object with the four required parameters matrixX, matrixY, matrix, and divisor.
import flash.filters.ConvolutionFilter;
import flash.display.BitmapData;
var matrixX:Number = 3;
var matrixY:Number = 3;
var matrix:Array = [1, 1, 1, 1, 1, 1, 1, 1, 1];
var divisor:Number = 9;
var filter:ConvolutionFilter = new ConvolutionFilter(matrixX, matrixY, matrix, divisor);
var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);
var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
myBitmapData.noise(128);
mc.onPress = function() {
myBitmapData.applyFilter(myBitmapData, myBitmapData.rectangle, new Point(0, 0), filter);
}
Version 8