加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

实验练习(3) flash player 11.3 的新功能

发布时间:2020-12-15 06:13:40 所属栏目:百科 来源:网络整理
导读:? ? ? ? ? ? ? 今天初步体现一个flash player 11.3 的新增的Api 功能,暂时使用一个新API作为这次的测试。 ? ? ? ? ? ? ? 我们知道PNG 的图片都是偏大的,在游戏里面使用若果PNG图片太大对于加载来讲是一种恶魔,不但降低用户的体现,而且消耗了带宽。在这次

? ? ? ? ? ? ? 今天初步体现一个flash player 11.3 的新增的Api 功能,暂时使用一个新API作为这次的测试。

? ? ? ? ? ? ? 我们知道PNG 的图片都是偏大的,在游戏里面使用若果PNG图片太大对于加载来讲是一种恶魔,不但降低用户的体现,而且消耗了带宽。在这次实验,使用BitmapData 的encode 方法 进行编码保存,这样的小功能 可以尝试将偏大PNg编码保存jpegxr 的编码,图片的质量会变得比较小。

? ? ? ? ? ? ? ? ? ? ??

? ?这种图尽量是不规则的PNG图片作为实验,周围保留比较多透明,在测试当中,发现压缩的空间比一张完整四四方方的PNG图片会压缩得明显一下。

? 在使用这种特性的时候,先导入JPEGXREncoderOptions 这个类,这个是设置jpegxr编码属性,第一个参数,填写数值越高 压缩比例越厉害,质量会变得更加差,但是文件会变得更加小。?

(参考:)http://labsdownload.adobe.com/pub/labs/flashplatformruntimes/shared/air3-3_flashplayer11-3_p1_releasenotes.pdf

encode(rect:Rectangle,EncoderOptions :Object,byteArray: ByteArray = null):
ByteArray;

JPEGXREncoderOptions?
(quantization:uint=20,colorSpace:String="auto",trimFlexBits:uint=0)

?

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.JPEGEncoderOptions;
	import flash.display.JPEGXREncoderOptions;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageQuality;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;

	public class flash13 extends Sprite
	{
		public function flash13()
		{
			 var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadAll);
			loader.load(new URLRequest("2.png"));
			function onLoadAll(e:Event):void
			{
				var bitmap:Bitmap=e.currentTarget.content;
				var bitmapdata:BitmapData=new BitmapData(bitmap.width,bitmap.height,true,0x00ff00);
				bitmapdata.draw(bitmap);
				var byteArray:ByteArray = new ByteArray();
				bitmapdata.encode(bitmapdata.rect,new JPEGXREncoderOptions(45),byteArray);
		        var file:FileReference=new FileReference();
			    file.save(byteArray,"testjxr.jpg");
				 
			}
			
		}
	}
}

保存之后的原本的PNG位图296K,保存之后变成了45K,质量受损程度没想象那么差,还是可以接受的。尝试对 JPEGXREncoderOptions(45) 对这个类的参数进行调整可以调试出不同的质量的效果。而保存之后的图片,若果想加载到flash 里面使用则需要使用flash player11版本则可以加载并呈现出内容。


下面尝试不同的参数效果。


下面是根据不同压缩比进行设置对比。可以看出 数值越高质量越差

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.JPEGEncoderOptions;
	import flash.display.JPEGXREncoderOptions;
	import flash.display.PNGEncoderOptions;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageQuality;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;

	[SWF( backgroundColor='0x000000',width='1000',height='600')]
	public class flash13 extends Sprite
	{
		private var loader2:Loader;
		public function flash13()
		{
			 var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadAll);
			loader.load(new URLRequest("3.jpg"));
			function onLoadAll(e:Event):void
			{
				var bitmap:Bitmap=e.currentTarget.content;
				
				for(var i:int=0;i<10;i++)
				{
					var bitmapdata:BitmapData=new BitmapData(bitmap.width,0x00ff00);
					bitmapdata.draw(bitmap);
					var byteArray:ByteArray = new ByteArray();
					bitmapdata.encode(bitmapdata.rect,new JPEGXREncoderOptions(i*10),byteArray);
					loader2=new Loader();
					loader2.loadBytes(byteArray);
					addChild(loader2);
					loader2.x=(i%5)*200;
					loader2.y=int(i/5)*280;
					
				}

			}
			
			
		}
	 
	}
}

这次更新,特性比较多,还有其他比较有意思的API,这就不一一测试了,有一些是针对IOs进行优化的,一些是音频方面。同样后续Air 版本 同样支持了MAc 模拟器,支持UsB的debug 测试,嘿嘿暂时用不上,对一些人来讲会用得上,但是最关心的性能优化上,还没提及到。在发展路线图来讲,第2季度,会推出新的版本的版本,也会对版本一些地方进行优化。

? ? ? ? 在flash player 12 版本的到来之时,我们还要等待效率上达到另外一个飞跃的版本,而目前版本还没用得上。暂时可以尝试一下,而我相信好的程序关键的因素是人,一个好的程序员是会克服一些因素提升flash 的性能。

? ? ? ? ?无论怎样说也好,我们更加期待的硬件上的提升。下一代的版本会让人感受到adobe 的真正诚意。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读