topical media & game development
#graphic-flex-image-effects-02-Flex-ConvolutionFilterTest.ax
#graphic-flex-image-effects-02-Flex-ConvolutionFilterTest.ax
[swf]
[flash]
flex
package {
import flash.filters.ConvolutionFilter;
import flash.filters.ColorMatrixFilter;
[SWF(width=550, height=400, backgroundColor=0xEEEEEE)]
Tests application of the ConvolutionFilter to a loaded image.
public class @ax-graphic-flex-image-effects-02-Flex-ConvolutionFilterTest extends graphic_flex_image_effects_02_Flex_ImageFilterTest {
Applies the ConvolutionFilter to the loaded bitmap.
override protected function applyFilter():void {
// the matrix to apply;
// this matrix creates a woodcut effect
var matrix:Array = [
-1, -1, -1, -1, -1,
-1, -1, -1, -1, -1,
-1, -1, 24, -1, -1,
-1, -1, -1, -1, -1,
-1, -1, -1, -1, -1
];
// calculate a divisor that is the sum of the matrix components
var divisor:Number = 0;
for each (var index:Number in matrix) {
divisor += index;
}
var filter:ConvolutionFilter = new ConvolutionFilter();
filter.matrixX = 5;
filter.matrixY = 5;
filter.matrix = matrix;
filter.divisor = 1;
filter.bias = 0;
// a matrix to invert the colors of the image
matrix = [
-1, 0, 0, 0, 255,
0, -1, 0, 0, 255,
0, 0, -1, 0, 255,
0, 0, 0, 1, 0
];
var colorFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix);
// both filters are applied to the loaded image
_bitmap.filters = [filter, colorFilter];
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.