flex 图片旋转

<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the Rotate effect. --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="Font.registerFont(myriad_font);"> <mx:Script> <!--[CDATA[ import flash.text.Font; [Embed("assets/MyriadWebPro.ttf", fontName="MyMyriad")] public var myriad_font:Class; [Bindable] public var angle:int=0; private function rotateImage():void { rotate.end(); angle += 45; rotate.play(); } ]]--> </mx:Script> <mx:Rotate id="rotate" angleFrom="{angle-45}" angleTo="{angle}" target="{myVB}"/> <mx:Panel title="Rotate Effect Example" horizontalAlign="center" width="75%" height="75%" layout="horizontal" paddingTop="5" paddingLeft="10" paddingRight="10" paddingBottom="5"> <mx:VBox id="myVB" width="50%" horizontalAlign="center"> <mx:Label text="Nokia 9930" fontFamily="MyMyriad" fontSize="14"/> <mx:Image id="img" source="@Embed(source='assets/Nokia_6630.png')"/> </mx:VBox> <mx:Text width="50%" color="blue" text="Click the button to rotate the image 45 degrees. Use an embedded font when applying the Rotate effect to text."/> <mx:ControlBar> <mx:Button label="Rotate 45 Degrees" click="rotateImage();"/> </mx:ControlBar> </mx:Panel> </mx:Application>

 

private function rotateImage():void { var bd:BitmapData = new BitmapData(img.content.height, img.content.width); bd.draw(img,null,null,null,null,true); // var ba:Bitmap=new Bitmap(bd,"auto",true); //Bitmap对象代表一个由像素组成的图形.用在这的目的:为了使bd中的图形信息以图片的格式显示出来, img.source=new Bitmap(scaleRight(bd)); } //向右旋转90度 public function scaleRight(bmp:BitmapData):BitmapData{ var m:Matrix = new Matrix(); m.rotate(Math.PI/2); m.translate(bmp.height,0); var bd:BitmapData = new BitmapData(bmp.height, bmp.width); bd.draw(bmp,m); return bd; } //向左旋转90度 public function scaleLeft(bmp:BitmapData):BitmapData{ var m:Matrix = new Matrix(); m.rotate(-Math.PI/2); m.translate(0,bmp.width); var bd:BitmapData = new BitmapData(bmp.height, bmp.width); bd.draw(bmp,m); return bd; }

第一种方法是图片容器Image的旋转,第二种方法是图片本身的旋转。


 

 

你可能感兴趣的:(function,image,Flex,application,button,Matrix)