AdjustDisplayObject 之 Mosaic

flash 图像显示

AdjustDisplayObject.rar

 

包含3个类,都是类函数

DisplayObjectAdjustColor 类包含对显示对象进行调整颜色的静态方法:亮度、对比度、饱和度和色相。

 

DisplayObjectFilters 类包含各种对显示对象进行过滤的常数值和方法,包括:相底反色效果、灰度、查找边缘、锐化、马赛克效果(两种方法)、浮雕效果、杂点效果、素描效果、水彩 效果、扩散效果(毛玻璃效果)、球面效果(鱼眼效果)、挤压效果、光照效果(高光效果)、PS里的颜色阈值效果、油画效果、旧照片效果。

 

BitmapTransformer 类包含各种对显示对象进行变形转换的方法,包括:裁剪、旋转、缩放、倾斜、对齐、分布。

 

用上面的mosaicFilter2来做一个flex中的马赛克的tweenEffect效果

 

  

 

package {
    import mx.effects.IEffectInstance;
    import mx.effects.TweenEffect;
    
    public class Mosaic extends TweenEffect {
        
        public function Mosaic(target:Object = null) {
            super(target);
            
            instanceClass = MosaicInstance;
        }
        
        public var scaleFrom:Number = 1;
        public var scaleTo:Number = 0.0002;
        
        override public function getAffectedProperties():Array {
            return [];
        }
        
        override protected function initInstance(inst:IEffectInstance):void {
            super.initInstance(inst);
            
            MosaicInstance(inst).scaleFrom = scaleFrom;
            MosaicInstance(inst).scaleTo = scaleTo;

        }
    }
}

 

 

package {
    import cn.riahome.filters.DisplayObjectFilter;
    
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.DisplayObject;
    
    import mx.core.Container;
    import mx.effects.Tween;
    import mx.effects.effectClasses.TweenEffectInstance;
    
    public class MosaicInstance extends TweenEffectInstance {
        
        private var mosaicBitmap:Bitmap;
        private var orginalBitmapData:BitmapData;
        
        //1 - 0.0001;
        public var scaleFrom:Number;
        public var scaleTo:Number;

        
        public function MosaicInstance(target:Object) {
            super(target);
            
            this.target = target;
        }
        
        override public function play():void {
            super.play();
            initMosaicBitmap();
            var tween:Tween = createTween(this, scaleFrom, scaleTo, duration); 
        }
        
        override public function onTweenUpdate(val:Object):void {
            mosaicBitmap.bitmapData = DisplayObjectFilter.mosaicFilter2(new Bitmap(orginalBitmapData),Number(val));
        }
        
        override public function onTweenEnd(val:Object):void {
            super.onTweenEnd(val);
            
            removeMosaicBitmap();
        }

        
        private function initMosaicBitmap():void {
            orginalBitmapData = new BitmapData(target.width,target.height,true,0);
            orginalBitmapData.draw(target as DisplayObject);
            
            mosaicBitmap = new Bitmap(orginalBitmapData);
            
            if(target is Container) {
                target.rawChildren.addChild(mosaicBitmap); 
            }
            else {
                target.addChild(mosaicBitmap);
            }
        }
        
        private function removeMosaicBitmap():void {
            if (target is Container)
				target.rawChildren.removeChild(mosaicBitmap); 
			else {
			    target.removeChild(mosaicBitmap); 
			}
				
		    mosaicBitmap.bitmapData.dispose();
		    mosaicBitmap.bitmapData = null;
		    mosaicBitmap = null;
		    orginalBitmapData = null;
        }
    }
}

你可能感兴趣的:(Flex,Flash)