ActionScript 3 AS3 Pixelate bitmapData

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3 Pixelate bitmapData相关的知识,希望对你有一定的参考价值。

package com.terrypaton.effect {

	import flash.display.*
	import flash.geom.Matrix;
	
	public class PixelateBitmap {
		public function PixelateBitmap ():void {
			_instance = this
			
		}
		public function setup (_bitmapData:BitmapData):void {
			_bmpData = _bitmapData
		}
		public function process (_source:BitmapData,amount:Number):void {
			
			var scaleFactor:Number = 1 / amount
			var bmpX:int = scaleFactor*_bmpData.width
			var bmpY:int = scaleFactor * _bmpData.height
			if (bmpX < 1) {
				bmpX = 10
			}
			if (bmpY < 1) {
				bmpY = 10
			}
			// scale image down
			_pixelateMatrix.identity ()
			_pixelateMatrix.scale (scaleFactor, scaleFactor)
			try {
				var _tempBmpData:BitmapData = new BitmapData (bmpX,bmpY,false,0xFF0000)
			}catch (e:Error) {
				trace("bmpX = "+bmpX)
				trace("bmpY = "+bmpY)
			}
			
			_tempBmpData.draw (_source, _pixelateMatrix)
			// now scale it back
			_pixelateMatrix.identity ()
			_pixelateMatrix.scale (amount, amount)
			
			_bmpData.draw(_tempBmpData,_pixelateMatrix)
		}
		public var _pixelateMatrix:Matrix = new Matrix()
		public var _bmpData:BitmapData
		
		public static function getInstance():PixelateBitmap {
			return _instance
		}
		public static var _instance:PixelateBitmap
	}
}

// Usage Example
//
// import com.terrypaton.effect.PixelateBitmap;
// 
// var myBitmapData:BitmapData = new myImage(320,240); // myImage is a bitmap in the library with Export for ActionScript set
// var myPixelatedBitmapData:BitmapData = new BitmapData(myBitmapData.width,myBitmapData.height);
// var myBitmap:Bitmap = new Bitmap(myPixelatedBitmapData);
// var pixelateBitmap:PixelateBitmap = new PixelateBitmap();
// pixelateBitmap.setup(myPixelatedBitmapData);
// 
// addChild(myBitmap);
// 
// addEventListener(Event.ENTER_FRAME, loop);
// function loop(event:Event):void {
// 	var amount:Number = 320 / mouseX;
// 	if (amount > 0) {
// 		pixelateBitmap.process(myBitmapData, amount);
// 	}
// }

以上是关于ActionScript 3 AS3 Pixelate bitmapData的主要内容,如果未能解决你的问题,请参考以下文章

[ActionScript 3.0] AS3.0 水面波纹效果

ActionScript 3 AS3:使用SWFObject2和AS3传递变量

ActionScript 3 克隆数组(AS3)

ActionScript 3 AS3序列化

ActionScript 3 As3初始上限

ActionScript 3 AS3 HTML清理