红绿反色:
代码
var filterObj = new flash.filters.ColorMatrixFilter();
filterObj.matrix = new Array(
0,0,1,0,0,
0,1,0,0,0,
1,0,0,0,0,
0,0,0,1,0);
displayObject.filters = [filterObj];
filterObj.matrix = new Array(
0,0,1,0,0,
0,1,0,0,0,
1,0,0,0,0,
0,0,0,1,0);
displayObject.filters = [filterObj];
黑白:
代码
var filterObj = new flash.filters.ColorMatrixFilter();
filterObj.matrix = new Array(
1/3,1/3,1/3,0,0,
1/3,1/3,1/3,0,0,
1/3,1/3,1/3,0,0,
0, 0, 0,1,0);
displayObject.filters = [filterObj];
filterObj.matrix = new Array(
1/3,1/3,1/3,0,0,
1/3,1/3,1/3,0,0,
1/3,1/3,1/3,0,0,
0, 0, 0,1,0);
displayObject.filters = [filterObj];
旧照片:
代码 var filterObj = new flash.filters.ColorMatrixFilter();
filterObj.matrix = new Array(
1/2,1/2,1/2,0,0,
1/3,1/3,1/3,0,0,
1/4,1/4,1/4,0,0,
0, 0, 0,1,0);
displayObject.filters = [filterObj];
通过图像边缘检测,可以把彩色图像或者视频 转换成黑白线条图。在AS中,可以使用卷积滤镜(ConvolutionFilter)实现简单的边缘检测。
上图就是实际的运行效果。
这个效果中使用了四个滤镜:
* 一个5x5的ConvolutionFilter,用来提取图像边缘;
* 一个ColorMatrixFilter,反转图像颜色,使黑底白线的图像变成白底黑线;
* 另一个ColorMatrixFilter去色,将色彩剔除;
* 使用最后一个ConvolutionFilter锐化,增强线条清晰度。
主要的功能代码:
References: