Flash player11.3新功能尝鲜

用代码来展示自己的学习历程:

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.JPEGEncoderOptions;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageQuality;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.net.FileReference;
	import flash.utils.ByteArray;
	
	/**
	 * ...
	 * Flash player 11.3新功能
	 * 参数 -swf-version=16,-target-player=11.3
	 * 代码参考 http://bbs.wefdc.com/thread-1635-1-1.html
	 * @author aisajiajiao
	 */
	public class TestFP113 extends Sprite
	{
		private var bmd:BitmapData;
		
		public function TestFP113()
		{
			var shape:Shape = new Shape();
			shape.graphics.beginFill(0xff0000,1);
			shape.graphics.drawCircle(0,0,100);
			shape.graphics.endFill();
			addChild(shape);
			
			bmd = new BitmapData(100,100);
			//新特性,绘制的时候可以设置质量
			bmd.drawWithQuality(shape,new Matrix(),null,null,null,false,StageQuality.LOW);
			
			var bmp:Bitmap = new Bitmap(bmd);
			bmp.x = 100;
			bmp.y = 100;
			addChild(bmp);
			
			stage.addEventListener(MouseEvent.CLICK,saveImage);
		}
		
		private function saveImage(e:MouseEvent):void
		{
			var bytes:ByteArray = new ByteArray();
			//新特性:AS原生的图片格式编码
			bmd.encode(bmd.rect,new JPEGEncoderOptions(50),bytes);
			var fileReference:FileReference = new FileReference();
			fileReference.save(bytes,"test.jpg");
		}
	}
}

以上只是部分新增的API,完整的看ASdoc

代码运行截图



你可能感兴趣的:(function,Flash,null,Class,import,Matrix)