<? xml version="1.0" encoding="utf-8" ?> < mx:Application xmlns:mx ="http://www.adobe.com/2006/mxml" layout ="absolute" creationComplete ="initApp()" > < mx:Label x ="20" y ="10" width ="173" height ="32" id ="tip_txt" /> < mx:Image x ="20" y ="50" width ="83" height ="110" id ="img" progress ="showProcess(event)" complete ="initImg()" /> < mx:Script > <![CDATA[ import flash.events.ProgressEvent; import flash.display.Bitmap; import flash.display.BitmapData; import mx.controls.Image; internal function initApp():void{ img.source="http://www.adobe.com/images/homepage/promos/60x45_flex.gif"; } internal function initImg():void{ tip_txt.text="图片加载完毕,开始复制"; var bd:BitmapData=new BitmapData(img.contentWidth,img.contentHeight,true,0); //当图片从外部加载时,要得到加载图片的长宽,必须使用Image控件的contentWidth和contentHeigt属性,而不是width和height属性 //第三个参数表示是否透明,第四个参数表示是否填充颜色。 //BitmapData对象负责操作像素数据,所有的像素方法都由它来完成。 var matrix:Matrix=new Matrix(1,0.2,0.2,-1,0,img.contentHeight); //Matrix是一个3*3的矩阵,用来实现对位图的放缩,旋转,坐标转换等动作 //第一个参数:水平方向的缩放比例 //第二个参数:水平方向的旋转角度 //第三个参数:垂直方向的旋转角度 //第四个参数:垂直方向的缩放比例 //第五,六个参数:水平方向和垂直方向的偏移量。 bd.draw(img,matrix); //draw(source:IBitmapDrawable,matrix:Matrix=null,colorTransform:ColorTransform=null,blendMode:String=null,clipRectangle=null,smoothing:Boolean=false) //source表示目标对象 //matrix是一个3*3的矩阵,用来实现对位图的放缩,旋转,坐标转换等动作 //colorTranform用来作色彩转换 //blendMode表示使用混合模式, //clipRect表示像素提取的范围,这是一个矩形,如果不设置,全部取出 //smoothing表示位图放缩时是否要平滑处理 var ba:Bitmap=new Bitmap(bd); //Bitmap对象代表一个由像素组成的图形.用在这的目的:为了使bd中的图形信息以图片的格式显示出来, var newImage:Image=new Image(); newImage.source=ba; newImage.x=img.x+200; newImage.y=img.y; this.addChild(newImage); } internal function showProcess(event:ProgressEvent):void{ var loaded:Number=event.bytesLoaded; var total:Number=event.bytesTotal; var p:Number=Math.floor(loaded/total*100); tip_txt.text="正在加载图片:"+p; } ]]> </ mx:Script > </ mx:Application >