import flash.filters.BlurFilter;
function feather(mc:MovieClip, degree:Number) {
//参数分别为图片元件和羽化程度(范围为0-100,数字越小,羽化程度越大)
degree = degree == undefined or degree<0 or degree>100 ? 90 : degree;//默认90
var depth:Number = getNextHighestDepth();
var blurMask:MovieClip = createEmptyMovieClip("blurMask"+depth, depth);
with (blurMask) {
beginFill(0);
lineTo(mc._width, 0);
lineTo(mc._width, mc._height);
lineTo(0, mc._height);
}
//这里画了一黑色的矩形块,大小与图片一样
var scale:Number = degree;
//设置模糊Mask图的尺寸
blurMask._xscale = blurMask._yscale=scale;
//是这张模糊Mask图要稍微比图片尺寸小一点
blurMask._x = mc._x+(mc._width-blurMask._width)/2;
blurMask._y = mc._y+(mc._height-blurMask._height)/2;
//设置模糊Mask图移到图片中心对齐
blurMask.filters = [new BlurFilter(blurMask._width*(100-scale)/100/2, blurMask._height*(100-scale)/100/2, 3)];
//这里前面两个参数表示横纵方向的模糊值(根据模糊Mask图的缩小尺寸来进行相应设置),第三个参数为品质,这里3表示高斯模糊
mc.cacheAsBitmap = true;
//这里设置图片的运行时位图缓存,是要害
mc.setMask(blurMask);
}
feather(M)
/************************************/
源文件下载:
羽化处理.rar加入论坛讨论学习中:
http://space.flash8.net/bbs/thread-339245-1-1.html