三个步骤:
1,导入图片
2,将图片放到舞台,转为影片剪辑,并起个实例名,比如pp
3,将下面代码复制到帧上即可,如果影片剪辑名为别的,则替换一下最后一行函数中的名字即可
效果:
代码与注释- //定义倒影函数
- function createRef(p_source:DisplayObject):void{
- //对源显示对象做上下反转处理
- var bd:BitmapData=new BitmapData(p_source.width,p_source.height,true,0);
- var mtx:Matrix=new Matrix();
- mtx.d=-1;mtx.ty=bd.height;
- bd.draw(p_source,mtx);
- //生成一个渐变遮罩
- var width:int=bd.width;
- var height:int=bd.height;
- mtx=new Matrix();
- mtx.createGradientBox(width,height,0.5 * Math.PI);
- var shape:Shape = new Shape();
- shape.graphics.beginGradientFill(GradientType.LINEAR,[0xff,0xff],[0.9,0.0],[0,150],mtx)
- shape.graphics.drawRect(0,0,width,height);
- shape.graphics.endFill();
- var mask_bd:BitmapData=new BitmapData(width,height,true,0);
- mask_bd.draw(shape);
- //生成最终效果
- bd.copyPixels(bd,bd.rect,new Point(0,0),mask_bd,new Point(0,0),false);
- //将倒影位图放在源显示对象下面
- var ref:Bitmap=new Bitmap();
- ref.x=p_source.x;
- ref.y=p_source.height+p_source.y;
- ref.bitmapData=bd;
- p_source.parent.addChild(ref);
- }
- //注意里面的参数为导入图像的实例名
- createRef(pp);
复制代码 源文件下载:图像倒影效果.rar(103.2KB)
|