• 使用Flex实现图片旋转。


    当用flex实现图片旋转的时候,遇到了这样的问题:截图之后,图片还是会继续旋转,应该是canvas这个还有旋转的角度,所以看到效果跟你截图保存下来的效果不一样。

    函数: 角度转换为弧度,这里面涉及到了数学的一些知识。 π/2是  90度的意思

    //  角度转换为弧度,  传递的值 degrees是角度值
    private function transformRadians(degrees:Number):Number 
    { 
        return (degrees * (Math.PI / 180)); 
    } 

    旋转函数

    //  旋转函数    value是角度值,   imgControl是Image控件ID。
    private function action_Rotate(value:String,imgControl:UIComponent):void 
    {
                    
        var radians:Number = transformRadians(Number(value));  
          //  确定旋转中心点
          var offsetWidth:Number = showPic.width/2;
          var offsetHeight:Number = showPic.height/2;
                    
          var tmpMatrix:Matrix = showPic.transform.matrix;
          tmpMatrix.translate(-offsetWidth, -offsetHeight);
          tmpMatrix.rotate(radians);
          tmpMatrix.translate(+offsetWidth, +offsetHeight);
                    
          imgControls.transform.matrix = tmpMatrix;
          tmpMatrix = null;
                    
          rotateDeg = imgControls.rotation;
                    
    }
    View Code

    旋转后要及时保存图片截图

    //  旋转截图,  传递:   imgControl是Image控件ID,   wrapPic是canvas控件ID
    private function showRotateImg(imgControl:UIComponent, wrapPic:UIComponent):void
    {
          var bmp:BitmapData = ImageSnapshot.captureBitmapData(wrapPic, new Matrix());
    
          imgControl.source = null;
          imgControl.source = new Bitmap(bmp);
    
          //  这里需要注意:截图完成了,需要将图片原来所有的旋转归零。对Matrix对象使用identity()这个函数。
          var tmpMatrix:Matrix = imgControl.transform.matrix;
          tmpMatrix.identity();
          imgControl.transform.matrix = tmpMatrix;
    }
    

      这里需要注意:截图完成了,需要将图片原来所有的旋转归零。对Matrix对象使用identity()这个函数。

    实现旋转的主要函数

  • 相关阅读:
    MYSQL 使用DBI
    mysql 更改数据目录
    Error Code: 1360
    org.hibernate.exception.GenericJDBCException: Could not open connection
    Error: Dynamic is undefined
    Unhandled event loop exception No more handles
    Count:858org.apache.jasper.JasperException: Unable to compile class for JSP
    Mysql --skip-grant-table
    第24章-启动 停止 和配置mysql
    Linux 6.2 x86_64 安装ipvs
  • 原文地址:https://www.cnblogs.com/xxjudfc/p/3715271.html
Copyright © 2020-2023  润新知