您的当前位置:首页正文

actionScript 3.0 图片裁剪及旋转

2024-11-09 来源:个人技术集锦

代码一:

  1. package 
  2.     import com.wdxc.ImageCut;
  3.     import com.wdxc.ImageRotation;
  4.     import flash.geom.Point;
  5.     import flash.geom.Rectangle;
  6.     import flash.net.URLLoader;
  7.     import flash.net.URLRequest;
  8.     import flash.events.* ;
  9.     import flash.display.*;
  10.     import flash.geom.* ;
  11.     import flash.net.*;
  12.     import flash.text.TextField;
  13.     import flash.utils.ByteArray;
  14.     import com.wdxc.util.* ;      
  15.     import fl.containers.ScrollPane;
  16.     import flash.display.Shape;
  17.     import fl.events.ScrollEvent;
  18.     import flash.external.ExternalInterface;
  19.     import flash.system.Security;
  20.     import flash.utils.Timer;
  21.     import flash.events.TimerEvent ;
  22.     import com.wdxc.* ;
  23.     
  24.     
  25.     /**  
  26.      * @author luqinglong
  27.      */ 
  28.     public class Main extends MovieClip
  29.     {
  30.         //存储加载进来的图片数据
  31.         private var _bitmap:Bitmap ;               
  32.         //进度条
  33.         private var _progressbar:TextField ;
  34.         
  35.         private var picname:String ; 
  36.             
  37.         public var _imageCut:ImageCut = new ImageCut() ;
  38.                
  39.         //场景引用
  40.         public static var SCENE:MovieClip ;
  41.            
  42.         public static var _handerState:int = 0 ;
  43.                
  44.             
  45.         public var pelsHint:TextField = new TextField(); 
  46.                        
  47.         public var photoid :String = "0"
  48.          
  49.         public var ir:ImageRotation ; 
  50.             
  51.         /**
  52.          * 原图和中图的压缩比例  
  53.          */    
  54.         public var picScale :Number = 2 ;
  55.                
  56.            
  57.         public function Main():void {           
  58.             flash.system.Security.allowDomain("*");         
  59.             
  60.             photoid = this.loaderInfo.parameters['photoid'];   
  61.                     
  62.             //photoid = "284186" ;    
  63.            
  64.             SCENE = this;           
  65.             
  66.             menu_mc.cut_btn.addEventListener(MouseEvent.MOUSE_DOWN, this._imageCut.startCutPic);
  67.          
  68.             menu_mc.rotate_btn.addEventListener(MouseEvent.MOUSE_DOWN, rotationHandler) ;  
  69.         
  70.             checkAvailable();   
  71.                   
  72.             this.addPelsHint();     
  73.             startLoadPic();       
  74.         }   
  75.                
  76.         /**
  77.          * 加入象素提醒  
  78.          */
  79.         private function addPelsHint():void {
  80.             this.addChild(pelsHint);      
  81.             //pelsHint.text = "象素不够" ;
  82.             pelsHint.x = 150 ; 
  83.             pelsHint.y = 0 ;                      
  84.             pelsHint.height = 20 ;           
  85.             this.pelsHint.width = 350 ; 
  86.             pelsHint.textColor =0xFF0000;
  87.         }
  88.           
  89.         public function setPelsHint(p:Number,hint:String):void {
  90.                                  
  91.             this.pelsHint.text = "像素:" + String(p) + "  " + hint  ;     
  92.                
  93.         }       
  94.            
  95.         private function rotationHandler(e:MouseEvent):void {    
  96.             ir = new ImageRotation() ;  
  97.             ir.x = menu_mc.x ;
  98.             ir.y = menu_mc.y ;     
  99.             this.stage.addChild(ir);    
  100.         }   
  101.         
  102.           
  103.         /**
  104.          * 得到最低象素值 。
  105.          */
  106.         /*
  107.         public function getMaxPels():Number {
  108.   
  109.             return this.plength/ 500 ;
  110.         }  */
  111.           
  112.         //public function setPelsScale(p:Number) {
  113.             //this.plength = p / 500 ;
  114.         //}
  115.               
  116.         
  117.           
  118.         public function set bitmap(bp:Bitmap):void {
  119.             this._bitmap = bp ;
  120.         } 
  121.             
  122.         public function get bitmap():Bitmap {
  123.             return this._bitmap ;
  124.         }
  125.                 
  126.         public function startLoadPic():void {
  127.                              
  128.             var param:URLVariables = new URLVariables() ; 
  129.             var url:String = "/photo/LoaderPhotoServlet";      
  130.             //var url:String = "http://localhost:8080//photo/LoaderPhotoServlet" ;
  131.                
  132.             param.random = Math.floor(Math.random() * 1000);                 
  133.             param.photoid = photoid ;           
  134.             //output.text = photoid ;
  135.             //url += Math.floor(Math.random() * 1000);
  136.             
  137.                 
  138.             var request:URLRequest = new URLRequest(url);   
  139.             request.data = param ;
  140.             var loader :Loader = new Loader();
  141.             loader.load(request);      
  142.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, picLoadCompleteHandler);
  143.         } 
  144.         /**  
  145.          * 导入二进制完成
  146.          * @param   e    
  147.          */    
  148.         private function picLoadCompleteHandler(e:Event):void {
  149.                
  150.             /**删除进度条*/    
  151.             if (Main._handerState == 1||Main._handerState==2) {
  152.                  this.delVagueBg();    
  153.                  delLoadingBar();
  154.                  calljs();
  155.             }           
  156.             Main._handerState = 0 ;
  157.               
  158.             /*
  159.             if (this._bitmap.bitmapData != null) {
  160.                 
  161.                 this._bitmap.bitmapData.dispose() ;   
  162.                 //this.removeChild(_bitmap);
  163.             } */          
  164.             
  165.             this._bitmap =  new Bitmap() ;          
  166.                      
  167.             var loader:Loader = e.target.loader as Loader;        
  168.               
  169.             var _bitmapdata:BitmapData = new BitmapData(loader.width, loader.height);
  170.             _bitmapdata.draw(loader); 
  171.                 
  172.                  
  173.             /**
  174.              * 判断横版照片,竖版照片
  175.              */ 
  176.             /*
  177.             if ( loader.height > loader.width) {
  178.                 //竖版照片  
  179.                 this.cutscaleFlag = Constant.VERTICAL ;    
  180.             } */  
  181.                
  182.                   
  183.                                 
  184.             this._bitmap.bitmapData = _bitmapdata;               
  185.             this.addChild(_bitmap);  
  186.             this.reset() ;       
  187.             //设置原图引用                 
  188.             this._imageCut.bitmap = this._bitmap ;                   
  189.             this.addChild(this._imageCut);
  190.                
  191.             e.currentTarget.removeEventListener(Event.COMPLETE, picLoadCompleteHandler); 
  192.                   
  193.         }     
  194.           
  195.            
  196.         
  197.         /** 
  198.          * 删除以前的Bitmapt对象,注入新的进去 。
  199.          */
  200.         public function removeBitmap():void {
  201.                      
  202.             this.removeChild(_bitmap);
  203.         }        
  204.         public function reset():void {  
  205.             this._bitmap.x = (Constant.LEFT_AREA_WIDTH-_bitmap.width)/2 ;
  206.             this._bitmap.y = (Constant.SCRENE_HEIGHT - _bitmap.height) / 2 ;
  207.         }
  208.         
  209.         public function checkAvailable():void {
  210.             if (ExternalInterface.available){
  211.                 try {    
  212.                     ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
  213.                     if (checkJavaScriptReady()) {
  214.                         //trace("JavaScript is ready./n");
  215.                     } else { 
  216.                                     
  217.                         //trace("JavaScript is not ready, creating timer./n");
  218.                         var readyTimer:Timer = new Timer(100, 0);
  219.                         readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
  220.                         readyTimer.start();       
  221.                     }
  222.                 }catch (error:SecurityError) {
  223.                     //trace("A SecurityError occurred: " + error.message + "/n");
  224.                     //output.text = "error1";
  225.                 }catch (error:Error) {  
  226.                     
  227.                     //trace("An Error occurred: " + error.message + "/n");
  228.                 }   
  229.             }else{   
  230.                 //trace("External interface is not available for this container.");
  231.             }
  232.          
  233.         } 
  234.          
  235.         private function timerHandler(event:TimerEvent):void {
  236.            
  237.             var isReady:Boolean = checkJavaScriptReady(); 
  238.             //output.appendText("123");
  239.             if (isReady) {              
  240.                 //trace("JavaScript is ready./n"); 
  241.                 Timer(event.target).stop();
  242.             }
  243.         }
  244.                   
  245.                               
  246.         private function receivedFromJavaScript(pid:String, plength:Number):void {       
  247.                             
  248.             //pelsHint.text = pid + "==" + plength ;
  249.             this.photoid = pid ;      
  250.               
  251.             //设置中图和原图的像素比
  252.             this.picScale = plength/500 ;     
  253.               
  254.             //this._bitmap.bitmapData.dispose();
  255.             //output.text = value ;      
  256.             removeBitmap();        
  257.             // 点击了裁剪按钮时
  258.             if (Main._handerState == 5) {
  259.                 _imageCut.removeCutMenu();    
  260.                  
  261.             }    
  262.             // 裁剪时候单击保存时候 
  263.             else if (Main._handerState == 6) {
  264.                 _imageCut.removeCutMenu();    
  265.                 _imageCut.removeHint();              
  266.             } else if (Main._handerState == 10) {
  267.                 ir.remove();
  268.             }  
  269.             
  270.      
  271.             
  272.             
  273.             //this._bitmap = null ;
  274.             startLoadPic();        
  275.         }
  276.         private function checkJavaScriptReady():Boolean {
  277.             var isReady:Boolean = ExternalInterface.call("isReady");
  278.             return isReady;
  279.         } 
  280.                   
  281.         public function calljs():void {
  282.             if (ExternalInterface.available) {     
  283.                 ExternalInterface.call("rationAndCropComplete""123");
  284.             }     
  285.         }
  286.           
  287.          
  288.         public var  _vaguebg:Sprite ;
  289.         public function addVagueBg():void { 
  290.             _vaguebg = new Sprite() ;          
  291.             _vaguebg.graphics.beginFill(0x000000);
  292.             _vaguebg.graphics.drawRect(0, 0, 770, 530);
  293.             _vaguebg.graphics.endFill();
  294.             _vaguebg.alpha = 0.5;                   
  295.                             
  296.             this.addChild(_vaguebg);    
  297.                 
  298.         }     
  299.         public function delVagueBg():void {  
  300.             this.removeChild(_vaguebg);
  301.         }      
  302.         
  303.         
  304.         public var loadingbar:Sprite ;  
  305.         public function addLoadingBar():void {
  306.             loadingbar = new LoadingBar();                 
  307.             this.addChild(loadingbar) ;    
  308.             loadingbar.x = 200 ;
  309.             loadingbar.y = 150 ;
  310.         }    
  311.               
  312.         public function delLoadingBar():void {
  313.             this.removeChild(loadingbar);
  314.         }
  315.     }   
  316. }

代码二:

  1. package com.wdxc {
  2.     import flash.display.Bitmap;
  3.     import flash.display.BitmapData;
  4.     import flash.events.* ; 
  5.     import flash.display.* ;
  6.     import flash.geom.Matrix; 
  7.     import flash.geom.Point;
  8.     import flash.geom.Rectangle;
  9.     import flash.printing.PrintJob;
  10.     import flash.ui.Mouse ; 
  11.     //import flash.utils.Timer; 
  12.     import flash.utils.* ; 
  13.     import com.wdxc.Constant ;
  14.     import fl.controls.* ;
  15.     /** 
  16.     * 图像裁剪
  17.     * @author luqinglong
  18.     */    
  19.     public class ImageCut extends Sprite{ 
  20.            
  21.         //原始图像数据数据
  22.         private var _bitmap:Bitmap ;
  23.         //裁剪区域   
  24.         private var _rect:Sprite ;   
  25.         //裁剪控制菜单
  26.         private var _cutMenu:CutMenu ;  
  27.         //拖动时光标图形
  28.         private var _cursor1:Sprite ;           
  29.         //拉伸时光标图形   
  30.         private var _cursor2:Sprite  ;        
  31.         //记录鼠标信息,  
  32.         private var _mouseInfo:MouseInfo = new MouseInfo() ;
  33.         //鼠标按下时,保存绘制矩形的信息
  34.         private var _tempObj:Object = new Object() ;   
  35.          
  36.         //预览时,临时保存图片数据 
  37.         private var _tempBitmapData:BitmapData ;
  38.           
  39.         private var bg1:Sprite  ;//预览加载背景时用,覆盖菜单
  40.          
  41.         //模糊背景
  42.         private  var _vaguebg:Sprite ;
  43.          
  44.         //裁剪比例         
  45.         private var _cutScale:Number  = 0 ;
  46.            
  47.         //宽和高度裁剪比例  
  48.         public var cutscaleFlag:int = Constant.HORIZONTAL;
  49.             
  50.         public var minPels:Number = 800 * 600;
  51.              
  52.         private var scaleInfo:String = "0";
  53.          
  54.         public function ImageCut() {     
  55.         }         
  56.             
  57.         /** 
  58.          * 创建光标,并使其不可见 。
  59.          */
  60.         private function createCursor():void {
  61.             _cursor1 = new Cursor1() ; 
  62.             _cursor1.x = mouseX ;
  63.             _cursor1.y = mouseY ; 
  64.             _cursor1.visible = false ;
  65.                  
  66.             _cursor2 = new Cursor2() ;
  67.             _cursor2.x = mouseX ;
  68.             _cursor2.y = mouseY ;    
  69.             _cursor2.visible = false ;          
  70.             
  71.             this.addChild(_cursor1);
  72.             this.addChild(_cursor2) ; 
  73.         } 
  74.                   
  75.         /** 
  76.          * 初始化,裁剪控制菜单
  77.          */  
  78.         private function createCutMenu():void {
  79.                 
  80.             //显示像素提醒 ;
  81.             Main.SCENE.pelsHint.visible = true ;
  82.             
  83.             _cutMenu = new CutMenu();         
  84.             _cutMenu.x = Main.SCENE.menu_mc.x ;
  85.             _cutMenu.y = Main.SCENE.menu_mc.y ;       
  86.                                   
  87.             this.addChild(_cutMenu);               
  88.             _cutMenu.cutok_btn.addEventListener(MouseEvent.CLICK, saveHint) ;  
  89.             _cutMenu.cutcancle_btn.addEventListener(MouseEvent.CLICK, cutCancle) ;    
  90.             _cutMenu.preview_btn.addEventListener(MouseEvent.CLICK, cutPreview) ;
  91.                
  92.             _cutMenu.rd5_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  93.             _cutMenu.rd6_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  94.             _cutMenu.rd62_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  95.             _cutMenu.rd7_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  96.             _cutMenu.rd8_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  97.             _cutMenu.rd10_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  98.             _cutMenu.rd12_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  99.             _cutMenu.rd16_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  100.             _cutMenu.rd18_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  101.             _cutMenu.rd20_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  102.             _cutMenu.rd24_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  103.             _cutMenu.rd30_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  104.             _cutMenu.rd40_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  105.             _cutMenu.rd0_mc.addEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  106.         }          
  107.                            
  108.         /**
  109.          * 创建裁剪框
  110.          */ 
  111.         private function createCutRect():void {
  112.              _rect = new Sprite();   
  113.              _rect.x = _bitmap.x ;   
  114.              _rect.y = _bitmap.y ;
  115.             /***设置裁剪区域边框样式*/           
  116.             _rect.graphics.lineStyle(Constant.BORDER, 0xFF0000, 0.8, true, LineScaleMode.NONE, CapsStyle.ROUND);
  117.             _rect.graphics.beginFill(0xCCFF00,0);           
  118.             _rect.graphics.drawRect(0,0,_bitmap.width-20,_bitmap.height-20);     
  119.             _rect.graphics.endFill();                
  120.             this.addChild(_rect);       
  121.         } 
  122.         
  123.         public function set bitmap(bp:Bitmap):void {
  124.             this._bitmap = bp ;
  125.         }    
  126.         public function get bitmap():Bitmap {
  127.             return this._bitmap ;
  128.         }
  129.         
  130.          /****        
  131.          * 开始裁剪。初始化裁剪工具。
  132.          * @param    e     
  133.          */        
  134.         public function startCutPic(e:MouseEvent):void 
  135.         {      
  136.             /**
  137.              * 判断横版照片,竖版照片
  138.              */  
  139.             if ( _bitmap.height > _bitmap.width) {
  140.                 //竖版照片  
  141.                 this.cutscaleFlag = Constant.VERTICAL ;    
  142.             } else {     
  143.                 this.cutscaleFlag = Constant.HORIZONTAL ;
  144.             }
  145.     
  146.             Main._handerState = 5;  
  147.             //cutpicing();
  148.             this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ; 
  149.             this.stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler) ;
  150.             this.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler) ;   
  151.             this.createCutMenu() ;    
  152.             this.createCutRect() ;      
  153.             this.createCursor() ;
  154.                         
  155.             //_cutMenu.RadioButtonGroup1.addEventListener(Event.CHANGE, changeHandler); 
  156.         }   
  157.         private function changeHandler(e:Event):void {  
  158.             //RadionButton  = e.target as RadionButton ;
  159.             trace(123);       
  160.         }
  161.           
  162.         /**
  163.          * 比例裁剪
  164.          */
  165.         private function  scaleSelectHandler(e:MouseEvent):void {
  166.             var rb:RadioButton = e.target as RadioButton;
  167.             //为横排照片  
  168.                      
  169.             switch(rb.value) {
  170.                 case "5" :      
  171.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 3.5):(3.5 / 5) ;
  172.                     scaleInfo = "5 : 3.5";  
  173.                     this.minPels = 800 * 600 ;
  174.                     break ;    
  175.                 case "6" :     
  176.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(3 / 2):(2 / 3) ;
  177.                     scaleInfo = "3 : 2";  
  178.                     this.minPels = 1024 * 768 ;       
  179.                     break ;  
  180.                 case "62":  
  181.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
  182.                     scaleInfo = "4 : 3";  
  183.                     this.minPels = 1024 * 768 ;
  184.                     break ;     
  185.                 case "7" :   
  186.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(7 / 5):(5 / 7) ;
  187.                     scaleInfo = "7 : 5";  
  188.                     this.minPels = 1280 * 960 ;
  189.                     break ;  
  190.                 case "8" :     
  191.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
  192.                     scaleInfo = "4 : 3";  
  193.                     this.minPels = 1280 * 960 ;  
  194.                     break ;
  195.                 case "10":         
  196.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 4):(4 / 5) ;
  197.                     scaleInfo = "5 : 4";  
  198.                     this.minPels = 1600 * 1200 ;
  199.                     break ; 
  200.                 case "12":     
  201.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(6 / 5):(5 / 6) ;
  202.                     scaleInfo = "6 : 5";  
  203.                     this.minPels = 1600 * 1200 ;
  204.                     break ;
  205.                 case "16":      
  206.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
  207.                     this.minPels = 2048 * 1953 ;
  208.                     scaleInfo = "4 : 3";  
  209.                     break ;
  210.                 case "18":    
  211.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(3 / 2):(2 / 3) ;
  212.                     this.minPels = 2048 * 1953 ;
  213.                     scaleInfo = "3 : 2";  
  214.                     break ;
  215.                 case "20":    
  216.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 4):(4 / 5) ;
  217.                     this.minPels = 2048 * 1953 ;
  218.                     scaleInfo = "5 : 4";  
  219.                     break ;
  220.                 case "24":    
  221.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(6 / 5):(5 / 6) ;
  222.                     this.minPels = 2048 * 1953 ;
  223.                     scaleInfo = "6 : 5";  
  224.                     break ;
  225.                 case "30":    
  226.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(5 / 4):(4 / 5) ;
  227.                     this.minPels = 2048 * 1953 ;
  228.                     scaleInfo = "5 : 4";  
  229.                     break ;     
  230.                 case "40":                 
  231.                     this._cutScale = (this.cutscaleFlag == Constant.HORIZONTAL)?(4 / 3):(3 / 4) ;
  232.                     this.minPels = 2048 * 1953 ;
  233.                     scaleInfo = "4 : 3";  
  234.                     break  
  235.                 case "0":                                     
  236.                     this._cutScale = 0;
  237.                     this.minPels = 800 * 600 ;
  238.                     scaleInfo = "0";   
  239.                     break ;   
  240.             }   
  241.             
  242.             this._rect.graphics.clear();
  243.             this._rect.x = _bitmap.x ; 
  244.             this._rect.y = _bitmap.y ;  
  245.             _rect.graphics.lineStyle(Constant.BORDER, 0xFF0000, 0.8, true, LineScaleMode.NONE, CapsStyle.ROUND);
  246.             _rect.graphics.beginFill(0xCCFF00, 0);    
  247.                  
  248.             if (this._cutScale == 0) {                  
  249.                           
  250.                 _rect.graphics.drawRect(0, 0, _bitmap.width-20,_bitmap.height-20); 
  251.             }else { 
  252.                 var w = _bitmap.width  ; 
  253.                 var h = w / this._cutScale ;
  254.                    
  255.                 /*按比例显示最大尺寸*/
  256.                 if (h < _bitmap.height) {
  257.                     _rect.graphics.drawRect(0,0,w,h); 
  258.                 }else {             
  259.                     _rect.graphics.drawRect(0,0,_bitmap.height*this._cutScale,_bitmap.height); 
  260.                 }  
  261.             }
  262.                 
  263.             _rect.graphics.endFill();  
  264.                       
  265.         }        
  266.          
  267.         private function cutCancle(e:MouseEvent):void {
  268.                  
  269.             Main._handerState = 0 ;
  270.             removeCutMenu();
  271.         }    
  272.         
  273.         /**   
  274.          * 保存裁剪应用   
  275.          */       
  276.         private function cutApplication(e:MouseEvent):void {   
  277.                
  278.             // 保存裁剪 导入条 
  279.             Main.SCENE.addLoadingBar();
  280.               
  281.             var server :ImageService = new ImageService();
  282.             server.photoid = Main.SCENE.photoid ;
  283.                   
  284.             var tempx:Number = Math.round(_rect.x - this._bitmap.x);
  285.             var tempy:Number = Math.round(_rect.y - this._bitmap.y) ;
  286.                      
  287.             server.submitCut(tempx, tempy, Math.round(_rect.width), Math.round(_rect.height),this.scaleInfo);
  288.      
  289.             this.removeCutMenu();       
  290.             _cutSaveHint.removeEventListener(MouseEvent.CLICK, removeHintHandler);
  291.             _cutSaveHint.removeEventListener(MouseEvent.CLICK, cutApplication);
  292.             
  293.             this.stage.removeChild(_cutSaveHint);  
  294.             
  295.             Main._handerState = 1 ;    
  296.             
  297.             //得到长边
  298.             var ml = _rect.width > _rect.height?_rect.width:_rect.height ;
  299.                   
  300.             //重新计算中图和大图的比例         
  301.             Main.SCENE.picScale = Main.SCENE.picScale * ml/500 ;
  302.                 
  303.             
  304.             
  305.         } 
  306.             
  307.         public var _cutSaveHint:CutSaveHint ;
  308.          
  309.          
  310.         /**
  311.          * 保存时候提示说明
  312.          * @param   e
  313.          */
  314.         private function saveHint(e:MouseEvent):void {
  315.                       
  316.             // = 背景和提示同时存在 
  317.             Main._handerState = 6 ;
  318.             
  319.             Main.SCENE.addVagueBg();
  320.             
  321.                 
  322.             _cutSaveHint = new CutSaveHint();
  323.                      
  324.             _cutSaveHint.x = (Constant.LEFT_AREA_WIDTH-_cutSaveHint.width)/2 ;
  325.             _cutSaveHint.y = 200 ;  
  326.                      
  327.             this.stage.addChild(_cutSaveHint);              
  328.                                                                            
  329.             _cutSaveHint.ok_btn.addEventListener(MouseEvent.CLICK, cutApplication);
  330.             _cutSaveHint.cancle1_btn.addEventListener(MouseEvent.CLICK,removeHintHandler);
  331.                  
  332.         
  333.             this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ; 
  334.         }       
  335.               
  336.         private function removeHintHandler(e:MouseEvent):void {
  337.                  
  338.             removeHint();
  339.     
  340.         }
  341.         
  342.         public function removeHint():void {
  343.                 
  344.             //单击裁剪
  345.             Main._handerState = 5 ;
  346.              
  347.             //删除提示按钮的监听器
  348.             _cutSaveHint.removeEventListener(MouseEvent.CLICK, removeHintHandler);
  349.             _cutSaveHint.removeEventListener(MouseEvent.CLICK, cutApplication);
  350.             this.stage.removeChild(_cutSaveHint);    
  351.                          
  352.                  
  353.             //戍边回复监听移动
  354.             this.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ;    
  355.                                
  356.             Main.SCENE.delVagueBg();
  357.         }
  358.                    
  359.             
  360.         /**
  361.          * 裁剪时预览
  362.          * @param   e
  363.          */
  364.         private function cutPreview(e:MouseEvent):void {
  365.                                     
  366.             
  367.             bg1 = new Sprite() ;          
  368.             bg1.graphics.beginFill(0x000000);
  369.             bg1.graphics.drawRect(0, 0, 770, 530);
  370.             bg1.graphics.endFill();
  371.             bg1.alpha = 0;               
  372.             bg1.x = Constant.LEFT_AREA_WIDTH+Constant.MIDDLE_AREA_WIDTH ; 
  373.             this.addChild(bg1);             
  374.         
  375.             //b保存一份副本,预览时候来用。      
  376.             _tempBitmapData  = this._bitmap.bitmapData.clone() ;
  377.             
  378.             
  379.             //存放裁剪出的新图片              
  380.             var cutbitmapdata:BitmapData = new BitmapData(Math.floor(_rect.width),Math.ceil(_rect.height)) ;
  381.          
  382.             //坐标转化,把坐标移到裁剪区域的位置,宽度和高度在cutbitmapdata里指定。 
  383.             var matrix:Matrix = new Matrix(1, 0, 0, 1, -Math.floor(_rect.x-_bitmap.x), -Math.floor(_rect.y-_bitmap.y));   
  384.             cutbitmapdata.draw(this._bitmap.bitmapData, matrix);  
  385.                  
  386.                      
  387.             this._bitmap.bitmapData.dispose() ;            
  388.             this._bitmap.bitmapData = cutbitmapdata ; 
  389.             this._rect.visible = false ;   
  390.             
  391.             Main.SCENE.reset();
  392.             setTimeout(previewCompletehandler, 2000) ;           
  393.         }     
  394.                   
  395.         private function previewCompletehandler():void {
  396.             this._bitmap.bitmapData.dispose();
  397.             this._bitmap.bitmapData = this._tempBitmapData ;
  398.             Main.SCENE.reset();        
  399.             this._rect.visible = true ;     
  400.             this.removeChild(bg1) ;         
  401.         }
  402.           
  403.         /**      
  404.          * 删除裁剪控制菜单 
  405.          */        
  406.         public function removeCutMenu():void {
  407.                  
  408.             //恢复原值 
  409.             Main._handerState = 0 ;
  410.                 
  411.             //象素不提醒 
  412.             Main.SCENE.pelsHint.visible = false ;
  413.             
  414.             _cutMenu.cutok_btn.removeEventListener(MouseEvent.MOUSE_DOWN, cutApplication);
  415.             _cutMenu.cutcancle_btn.removeEventListener(MouseEvent.MOUSE_DOWN, cutCancle) ; 
  416.                        
  417.              /*删除裁剪比例监听*/
  418.             _cutMenu.rd5_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  419.             _cutMenu.rd6_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  420.             _cutMenu.rd62_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  421.             _cutMenu.rd7_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  422.             _cutMenu.rd8_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  423.             _cutMenu.rd10_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  424.             _cutMenu.rd12_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  425.             _cutMenu.rd16_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  426.             _cutMenu.rd18_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  427.             _cutMenu.rd20_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  428.             _cutMenu.rd24_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  429.             _cutMenu.rd30_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  430.             _cutMenu.rd40_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  431.             _cutMenu.rd0_mc.removeEventListener(MouseEvent.CLICK, scaleSelectHandler) ;
  432.             this._cutScale = 0 ;    
  433.             
  434.     
  435.             this.stage.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler) ;
  436.             this.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler) ;
  437.             this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler) ; 
  438.                  
  439.             this.removeChild(_cutMenu) ;
  440.             this.removeChild(_rect) ;    
  441.             this.removeChild(_cursor1); 
  442.             this.removeChild(_cursor2) ;
  443.         }
  444.           
  445.          
  446.         /**  
  447.          * 鼠标按下处理
  448.          * @param   e
  449.          */
  450.         private function mouseDownHandler(e:MouseEvent):void { 
  451.             
  452.             /*保存按下前状态**/  
  453.             this._tempObj.width = _rect.width-Constant.BORDER ;
  454.             this._tempObj.height = _rect.height-Constant.BORDER ;
  455.             this._tempObj.x = _rect.x ;       
  456.             this._tempObj.y = _rect .y ;        
  457.              
  458.             /*鼠标为按下状态*/
  459.             this._mouseInfo.state = Constant.MOUSE_DOWN ;
  460.         }     
  461.         private function mouseUpHandler(e:MouseEvent):void {
  462.             _rect.stopDrag();     
  463.             /*状态设置为弹起状态**/
  464.             this._mouseInfo.state = Constant.MOUSE_UP ;
  465.         }         
  466.         
  467.         /**
  468.          * 鼠标移动
  469.          * @param   e       
  470.          */
  471.         private function mouseMoveHandler(e:MouseEvent):void {
  472.             Mouse.hide() ; 
  473.             this._cursor1.visible = false ;
  474.             this._cursor2.visible = false ; 
  475.              
  476.             /*拖动左边界*/
  477.             if (_mouseInfo.isStartLeftDrag()) {
  478.                 this.resetCursorPosition(Constant.CURSOR_HORIZONTAL) ;
  479.                 this.repaint(Constant.LEFT);
  480.             } 
  481.             /*拖动右边界*/
  482.             else if(_mouseInfo.isStartRightDrag()) { 
  483.                 this.resetCursorPosition(Constant.CURSOR_HORIZONTAL); 
  484.                 this.repaint(Constant.RIGHT);     
  485.             } 
  486.             /*拖动上边界*/
  487.             else if(_mouseInfo.isStartUpDrag()) { 
  488.                 this.resetCursorPosition(Constant.CURSOR_VERTICAL); 
  489.                 this.repaint(Constant.UP);     
  490.             } 
  491.             /*拖动下边界*/    
  492.             else if(_mouseInfo.isStartDownDrag()) { 
  493.                 this.resetCursorPosition(Constant.CURSOR_VERTICAL); 
  494.                 this.repaint(Constant.DOWN);      
  495.             } 
  496.             /*拖动整个区域*/ 
  497.             else if (_mouseInfo.isStartMiddleDrag()) {
  498.                 this.resetCursorPosition(Constant.CURSOR_MOVE); 
  499.                 this.dragHandler();   
  500.             } 
  501.             /*拖动左上角*/
  502.             else if (_mouseInfo.isStratLeftUPDrag()) {
  503.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT) ;
  504.                 this.repaint(Constant.LEFT_UP) ;
  505.             } 
  506.             /*拖动左下角*/
  507.             else if (_mouseInfo.isStratLeftDownDrag()) {
  508.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT) ;
  509.                 this.repaint(Constant.LEFT_DOWN) ;
  510.             }
  511.             /*拖动右上角*/
  512.             else if (_mouseInfo.isStratRightUPDrag()) {
  513.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT) ;
  514.                 this.repaint(Constant.RIGHT_UP) ;
  515.             }           
  516.             /*拖动右下角*/
  517.             else if (_mouseInfo.isStratRightDownDrag()) {
  518.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT) ;
  519.                 this.repaint(Constant.RIGHT_DOWN) ;
  520.             }            
  521.             /*鼠标在左上角**/
  522.             else if (isLeftUpAngle()) {
  523.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT);
  524.                 this._mouseInfo.position = Constant.LEFT_UP ; 
  525.                  
  526.             }
  527.             /*鼠标在左下角**/
  528.             else if (isLeftDownAngle()) {
  529.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT);
  530.                 this._mouseInfo.position = Constant.LEFT_DOWN ; 
  531.                  
  532.             }
  533.             /*鼠标在右上角**/
  534.             else if (isRightUpAngle()) {
  535.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_RIGHT);
  536.                 this._mouseInfo.position = Constant.RIGHT_UP ; 
  537.                  
  538.             }    
  539.             /*鼠标在右下角**/ 
  540.             else if (isRightDownAngle()) {
  541.                 this.resetCursorPosition(Constant.CURSOR_DIAGONAL_LEFT);
  542.                 this._mouseInfo.position = Constant.RIGHT_DOWN ;     
  543.                  
  544.             }
  545.                          
  546.             /*鼠标在左边界**/
  547.             else if (isLeftEdge()) {  
  548.                 this.resetCursorPosition(Constant.CURSOR_HORIZONTAL);      
  549.                 this._mouseInfo.position = Constant.LEFT ;
  550.          
  551.             }       
  552.             /*鼠标在右边界**/ 
  553.             else if (isRightEdge()) {        
  554.                 this.resetCursorPosition(Constant.CURSOR_HORIZONTAL);    
  555.                 this._mouseInfo.position = Constant.RIGHT ;   
  556.             }  
  557.             /*鼠标在上边界**/ 
  558.             else if (isUpEdge()) {   
  559.                 this.resetCursorPosition(Constant.CURSOR_VERTICAL);   
  560.                 this._mouseInfo.position = Constant.UP ; 
  561.             }           
  562.             /*鼠标在下边界**/ 
  563.             else if (isDownEdge()) {  
  564.                 this.resetCursorPosition(Constant.CURSOR_VERTICAL);   
  565.                 this._mouseInfo.position = Constant.DOWN ; 
  566.             } 
  567.             /* 鼠标在裁剪区域里。*/
  568.             else if (this.isInCutRect()) { 
  569.                 this.resetCursorPosition(Constant.CURSOR_MOVE); 
  570.                 this._mouseInfo.position = Constant.MIDDLE ;
  571.             }    
  572.             else {          
  573.                 Mouse.show () ;
  574.             }       
  575.             e.updateAfterEvent();
  576.             
  577.               
  578.             /*象素提示**/
  579.             this.pelsHint();        
  580.             
  581.         }   
  582.         
  583.         private function pelsHint():void {                           
  584.             var p = _rect.width * _rect.height * Main.SCENE.picScale * Main.SCENE.picScale ;
  585.             p = Math.round(p);           
  586.             if ( p < this.minPels) {       
  587.                 Main.SCENE.setPelsHint(p,"像素太低,继续裁剪将会影响照片的冲印质量。");    
  588.             }else {                 
  589.                 Main.SCENE.setPelsHint(p,""); 
  590.             }
  591.               
  592.         }
  593.         
  594.          /**    
  595.           * 重绘裁剪区域 。
  596.           * @param  state 
  597.           */
  598.         private function repaint(state:uint):void {  
  599.             this._rect.graphics.clear() ;               
  600.             _rect.graphics.lineStyle(Constant.BORDER, 0xFF0000, 0.8, true, LineScaleMode.NONE, CapsStyle.ROUND);
  601.             _rect.graphics.beginFill(0xCCFF00, 0);      
  602.             //var h:Number = 0 ;
  603.             //var w:Number = 0 ;        
  604.             switch(state) {        
  605.                 case Constant.LEFT:       
  606.                     this.leftDragHandler() ;
  607.                     break;  
  608.                 case Constant.RIGHT:      
  609.                      this.rightDragHandler();
  610.                     break ;   
  611.                 case Constant.UP:  
  612.                      this.upDragHandler();
  613.                      break ;                    
  614.                 case Constant.DOWN:  
  615.                     /*下端拖动*/
  616.                     downDragHandler();
  617.                     break;     
  618.                 case Constant.LEFT_UP:  
  619.                     this.leftUpDragHandler() ;            
  620.                     break;       
  621.                 case Constant.LEFT_DOWN:  
  622.                     /*左下角拖动*/  
  623.                     this.leftDownDragHandler();
  624.                     break;       
  625.                 case Constant.RIGHT_UP:   
  626.                     /*右上角拖动*/  
  627.                     this.rightUpDragHandler();
  628.                     break;            
  629.                 case Constant.RIGHT_DOWN:    
  630.                      /*右下角拖动*/      
  631.                     this.rightDownDragHandler();
  632.                     break;                      
  633.              }        
  634.             _rect.graphics.endFill();   
  635.         }  
  636.           
  637.         /*左端拖动处理*/     
  638.         private function leftDragHandler():void {
  639.             var w = 0 ;
  640.             var h = 0; 
  641.             if(this._cutScale!=0) {  
  642.                       
  643.                 _rect.x = mouseX < _bitmap.x?_bitmap.x:mouseX ;       
  644.                 _rect.x = _rect.x >= (_tempObj.width + _tempObj.x)?(_tempObj.width + _tempObj.x):_rect.x ;  
  645.                 w = _tempObj.width + _tempObj.x - _rect.x ;  
  646.                 h = w / this._cutScale ;
  647.                           
  648.                 var h2 = this._bitmap.height+this._bitmap.y - this._tempObj.y ;   
  649.                 if(h>=h2){                                         
  650.                     _rect.x = this._tempObj.x + this._tempObj.width -h2*this._cutScale;
  651.                     w = _tempObj.width + _tempObj.x - _rect.x ;  
  652.                     _rect.graphics.drawRect(0, 0, w, h2 );         
  653.                 }     
  654.                 else {
  655.                     _rect.graphics.drawRect(0, 0, w , h );   
  656.                 }
  657.   
  658.             }       
  659.             else {
  660.                  /*左端拖动*/          
  661.                 _rect.x = mouseX < _bitmap.x?_bitmap.x:mouseX ;       
  662.                 _rect.x = _rect.x >= (_tempObj.width + _tempObj.x)?(_tempObj.width + _tempObj.x):_rect.x ;   
  663.                 _rect.graphics.drawRect(0, 0, _tempObj.width + _tempObj.x - _rect.x, _tempObj.height);   
  664.              
  665.             }
  666.         }
  667.           
  668.         private function rightDragHandler():void {
  669.             var w:Number = 0 ;
  670.             var h:Number = 0 ;  
  671.             if (this._cutScale != 0) {
  672.                 /*右端拖动*/       
  673.                 w = mouseX > (w = (_bitmap.x + _bitmap.width))?w:mouseX ;
  674.                 w = w <= this._tempObj.x?_tempObj.x:w ;   
  675.                  
  676.                 //宽度
  677.                 w =  w -this._tempObj.x ;    
  678.                 h = w/ this._cutScale ;
  679.                 _rect.y = _tempObj.height + _tempObj.y - h;
  680.                 
  681.                 if (_rect.y < _bitmap.y) {                       
  682.                     h = _tempObj.height + _tempObj.y -_bitmap.y ;
  683.                     _rect.y = _bitmap.y ;            
  684.                     w =  h * this._cutScale ; 
  685.                     //w = w - this._tempObj.x ;          
  686.                     
  687.                     //trace("h=="+h); 
  688.                     
  689.                 }
  690.                 //trace("_rect.y=="+_rect.y+" bitmap.y=="+_bitmap.y);
  691.                      
  692.                 _rect.graphics.drawRect(0, 0, w,h);   
  693.                   
  694.             } 
  695.             else { 
  696.                 /*右端拖动,任意裁剪*/   
  697.                 w = mouseX > (w = (_bitmap.x + _bitmap.width))?w:mouseX ;
  698.                 w = w <= this._tempObj.x?_tempObj.x:w ;   
  699.                 _rect.graphics.drawRect(0, 0, w -this._tempObj.x, _tempObj.height);  
  700.             }
  701.                     
  702.         }
  703.           
  704.         /**
  705.          * 上端拖动处理
  706.          */   
  707.         private function upDragHandler():void {
  708.             
  709.             if (this._cutScale != 0) {
  710.                 /*按一定比例裁剪**/ 
  711.                 _rect.y = (mouseY < _bitmap.y)?_bitmap.y:mouseY;      
  712.                 _rect.y = _rect.y >=(_tempObj.height + _tempObj.y)?(_tempObj.height + _tempObj.y): _rect.y ;  
  713.                     
  714.                 var h = _tempObj.height + _tempObj.y-_rect.y ;
  715.                 var w = h * this._cutScale ;        
  716.                        
  717.                 _rect.x = _tempObj.x + _tempObj.width - w ;
  718.                  
  719.                 /**
  720.                  * 超过最左边
  721.                  */
  722.                 if (_rect.x < _bitmap.x) {  
  723.                     w = _tempObj.x + _tempObj.width - _bitmap.x ;
  724.                     _rect.x = _bitmap.x ;   
  725.                     
  726.                     h = w / this._cutScale ;
  727.                              
  728.                     _rect.y = _tempObj.y + _tempObj.height - h ;
  729.                 }
  730.                   
  731.                 _rect.graphics.drawRect(0, 0,w,h);  
  732.     
  733.             }else {
  734.                 /*任意尺寸裁剪**/
  735.                 _rect.y = (mouseY < _bitmap.y)?_bitmap.y:mouseY;      
  736.                 _rect.y = _rect.y >=(_tempObj.height + _tempObj.y)?(_tempObj.height + _tempObj.y): _rect.y ;  
  737.                 _rect.graphics.drawRect(0, 0, _tempObj.width,_tempObj.height+_tempObj.y-_rect.y);  
  738.             }
  739.         }
  740.              
  741.         
  742.         /**
  743.          * 下端拖动处理
  744.          */ 
  745.         private function downDragHandler():void {
  746.             var h = 0 ;
  747.             var w = 0;
  748.             if (this._cutScale != 0) {
  749.                 h = mouseY > (h = (_bitmap.y + _bitmap.height))?h:mouseY ;
  750.                 h = h <= this._tempObj.y?_tempObj.y:h ;  
  751.                 //高度
  752.                 h = h - _tempObj.y ;
  753.                 w = h * this._cutScale ;  
  754.                                     
  755.                 if ((w + _tempObj.x) >= (_bitmap.width+_bitmap.x)) {
  756.                     w = _bitmap.x + _bitmap.width - _rect.x ;
  757.                     h = w / this._cutScale ;
  758.                          
  759.                 }   
  760.                 _rect.graphics.drawRect(0, 0, w, h);
  761.             }else {
  762.                 h = mouseY > (h = (_bitmap.y + _bitmap.height))?h:mouseY ;
  763.                 h = h <= this._tempObj.y?_tempObj.y:h ;  
  764.                 _rect.graphics.drawRect(0, 0, _tempObj.width, h-_tempObj.y);
  765.             }
  766.         }
  767.           
  768.         /** 
  769.          * 左上拖动处理
  770.          */
  771.         private function leftUpDragHandler():void {
  772.             
  773.             if (this._cutScale != 0) {
  774.                 this.upDragHandler();
  775.             }else {
  776.                 /*左上角拖动*/    
  777.                 _rect.x = mouseX <= _bitmap.x?_bitmap.x:mouseX ;   
  778.                 _rect.y = (mouseY <= _bitmap.y)?_bitmap.y:mouseY;  
  779.                 
  780.                 var w = _tempObj.width + _tempObj.x ;
  781.                 var h = _tempObj.height + _tempObj.y ;
  782.                 _rect.x = _rect.x >= (w)?(w):_rect.x ; 
  783.                 _rect.y = _rect.y >=(h)?(h): _rect.y ; 
  784.                 _rect.graphics.drawRect(0, 0, w-_rect.x,h-_rect.y);   
  785.             } 
  786.         }
  787.               
  788.         /**
  789.          * 左下按比例拖动处理
  790.          */
  791.         private function leftDownDragHandler():void {
  792.             if (this._cutScale != 0) {
  793.                 this.leftDragHandler();
  794.             }else { 
  795.                 _rect.x = mouseX <= _bitmap.x?_bitmap.x:mouseX ;   
  796.                  _rect.x = _rect.x >= (_tempObj.width + _tempObj.x)?(_tempObj.width + _tempObj.x):_rect.x ;     
  797.                 var h = mouseY > (h = (_bitmap.y + _bitmap.height))?h:mouseY ;
  798.                 h = h <= this._tempObj.y?_tempObj.y:h ;    
  799.                 _rect.graphics.drawRect(0, 0, _tempObj.width + _tempObj.x - _rect.x,h-_tempObj.y);   
  800.             } 
  801.         }   
  802.         
  803.         private function rightDownDragHandler():void {
  804.             if (this._cutScale != 0) {
  805.                 this.downDragHandler();   
  806.             }else {     
  807.                 var w = mouseY > (w = (_bitmap.y + _bitmap.height))?w:mouseY ;
  808.                 w = w <= this._tempObj.y?_tempObj.y:w ;   
  809.                 var h = mouseX > (h = (_bitmap.x + _bitmap.width))?h:mouseX ;
  810.                 h = h <= this._tempObj.x?_tempObj.x:h    
  811.                 _rect.graphics.drawRect(0, 0, h -this._tempObj.x, w-_tempObj.y);         
  812.             }      
  813.         }  
  814.            
  815.         private function rightUpDragHandler():void {
  816.             if (this._cutScale != 0) {
  817.                 this.rightDragHandler();   
  818.             }else {   
  819.                 _rect.y = (mouseY < _bitmap.y)?_bitmap.y:mouseY;      
  820.                 _rect.y = _rect.y >=(_tempObj.height + _tempObj.y)?(_tempObj.height + _tempObj.y): _rect.y ;     
  821.                  var h = mouseX > (h = (_bitmap.x + _bitmap.width))?h:mouseX ;
  822.                  h = h <= this._tempObj.x?_tempObj.x:h   
  823.                 _rect.graphics.drawRect(0, 0, h -this._tempObj.x,_tempObj.height+_tempObj.y-_rect.y);   
  824.              
  825.             }     
  826.         }
  827.            
  828.         /**     
  829.          * 重新设置光标的位置,形状 。
  830.          * @param   p     
  831.          */
  832.         private function resetCursorPosition(cursor:uint):void {
  833.             /*移动状态*/
  834.             if (cursor == Constant.CURSOR_MOVE) {
  835.                 this._cursor1.x = mouseX ; 
  836.                 this._cursor1.y = mouseY ; 
  837.                 this._cursor1.visible = true ;  
  838.                 return ;   
  839.             }
  840.             this._cursor2.x = mouseX ;
  841.             this._cursor2.y = mouseY ; 
  842.             this._cursor2.visible = true ;        
  843.             switch(cursor) {
  844.                 case Constant.CURSOR_HORIZONTAL: 
  845.                     _cursor2.rotation = 0 ;
  846.                     break ; 
  847.                 case Constant.CURSOR_VERTICAL:   
  848.                     _cursor2.rotation = 90 ;
  849.                     break ;
  850.                 case Constant.CURSOR_DIAGONAL_LEFT:
  851.                     _cursor2.rotation = 45 ;
  852.                     break ; 
  853.                 case Constant.CURSOR_DIAGONAL_RIGHT:   
  854.                     _cursor2.rotation = 135 ;
  855.                     break ;
  856.             }
  857.         } 
  858.         
  859.         /** 
  860.          * 拖动 裁剪区域
  861.          */ 
  862.         private function dragHandler():void {
  863.             //裁剪区域移动范围,不能超过原图区域。 
  864.             var _rectangle:Rectangle = new Rectangle();
  865.             _rectangle.x = _bitmap.x ;
  866.             _rectangle.y = _bitmap.y ; 
  867.             _rectangle.width = this._bitmap.width-_rect.width ; 
  868.             _rectangle.height = this._bitmap.height-_rect.height ;       
  869.             _rect.startDrag(false, _rectangle);                     
  870.         }
  871.         
  872.         /**   
  873.          * 检查光标是否在左边界上  
  874.          * @return boolean
  875.          */                 
  876.         private function isLeftEdge():Boolean {
  877.             
  878.             /**检查左边界*/          
  879.             if (mouseX>=(this._rect.x - Constant.ACTIVERANGE) && 
  880.                 mouseX<=(this._rect.x + Constant.ACTIVERANGE) &&   
  881.                 mouseY>this._rect.y &&    
  882.                 mouseY<(this._rect.y +this._rect.height)) {
  883.                     return true ;          
  884.             }              
  885.             return false ;   
  886.         } 
  887.          
  888.         /**
  889.          * 检查光标是否在右边界上
  890.          */  
  891.         private function isRightEdge():Boolean {
  892.             if (mouseX>=(this._rect.x + this._rect.width - Constant.ACTIVERANGE) && 
  893.                 mouseX<=(this._rect.x+this._rect.width + Constant.ACTIVERANGE) &
  894.                 mouseY>this._rect.y&& 
  895.                 mouseY<(this._rect.y+this._rect.height)) {
  896.                     return true ;             
  897.             }      
  898.             return false ;
  899.         }
  900.          
  901.         /** 
  902.          * 检查光标是否在上边界上 。
  903.          * @return boolean .
  904.          */  
  905.         private function isUpEdge():Boolean { 
  906.             if (mouseX > this._rect.x && mouseX < (this._rect.x + _rect.width) &
  907.                 mouseY > (_rect.y - Constant.ACTIVERANGE) && 
  908.                 mouseY<(_rect.y+Constant.ACTIVERANGE)) {
  909.                 return true ;           
  910.             } 
  911.             return false ;
  912.         }
  913.         /** 
  914.          * 检查光标是否在下边界上 。
  915.          * @return boolean .
  916.          */ 
  917.         private function isDownEdge():Boolean { 
  918.             if (mouseX > this._rect.x && mouseX < (this._rect.x + _rect.width) &
  919.                 mouseY > (_rect.y + _rect.height - Constant.ACTIVERANGE) && 
  920.                 mouseY<(_rect.y+_rect.height+Constant.ACTIVERANGE)) {
  921.                 return true ;
  922.             } 
  923.             return false ;
  924.         }
  925.         /**   
  926.          * 检查光标是否在左上角 。
  927.          * @return boolean .   
  928.          */ 
  929.         private function isLeftUpAngle():Boolean { 
  930.             if (mouseX > (this._rect.x-Constant.ACTIVERANGE) && mouseX < (this._rect.x +Constant.ACTIVERANGE) &
  931.                 mouseY > (_rect.y  - Constant.ACTIVERANGE) && 
  932.                 mouseY<(_rect.y+Constant.ACTIVERANGE)) {        
  933.                 return true ;
  934.             }  
  935.             return false ;
  936.         }
  937.         /**    
  938.          * 检查光标是否在左下角 。
  939.          * @return boolean .   
  940.          */ 
  941.         private function isLeftDownAngle():Boolean { 
  942.             if (mouseX > (this._rect.x-Constant.ACTIVERANGE) && mouseX < (this._rect.x +Constant.ACTIVERANGE) &
  943.                 mouseY > (_rect.y+_rect.height  - Constant.ACTIVERANGE) && 
  944.                 mouseY<(_rect.y+_rect.height+Constant.ACTIVERANGE)) {        
  945.                 return true ; 
  946.             }  
  947.             return false ;
  948.         }   
  949.         /**    
  950.          * 检查光标是否在右上角 。
  951.          * @return boolean .   
  952.          */       
  953.         private function isRightUpAngle():Boolean { 
  954.             if (mouseX > (this._rect.x + _rect.width - Constant.ACTIVERANGE) && 
  955.                 mouseX < (this._rect.x+_rect.width +Constant.ACTIVERANGE) &
  956.                 mouseY > (_rect.y- Constant.ACTIVERANGE) && 
  957.                 mouseY<(_rect.y+Constant.ACTIVERANGE)) {        
  958.                 return true ; 
  959.             }      
  960.             return false ;
  961.         }
  962.         /**     
  963.          * 检查光标是否在右下角 。
  964.          * @return boolean .   
  965.          */        
  966.         private function isRightDownAngle():Boolean { 
  967.             if (mouseX > (this._rect.x + _rect.width - Constant.ACTIVERANGE) && 
  968.                 mouseX < (this._rect.x+_rect.width +Constant.ACTIVERANGE) &
  969.                 mouseY > (_rect.y+_rect.height- Constant.ACTIVERANGE) && 
  970.                 mouseY<(_rect.y+_rect.height+Constant.ACTIVERANGE)) {        
  971.                 return true ;    
  972.             }      
  973.             return false ;
  974.         }       
  975.           
  976.         /**  
  977.          * 判断光标标是否在裁剪区域里面
  978.          * @return boolean 
  979.          */          
  980.         private function isInCutRect():Boolean {   
  981.             if (mouseX>(this._rect.x + Constant.ACTIVERANGE) && 
  982.                 mouseX<(this._rect.x + this._rect.width - Constant.ACTIVERANGE) &
  983.                 mouseY>(this._rect.y + Constant.ACTIVERANGE) &&    
  984.                 mouseY<(this._rect.y + this._rect.height -Constant.ACTIVERANGE)) {
  985.                     return true ;
  986.             }   
  987.             return false ;  
  988.         }
  989.     }
  990. }

代码三:

  1. package com.wdxc {
  2.     import flash.display.MovieClip;
  3.     import flash.display.Sprite
  4.     import flash.display.* ;
  5.     import flash.events.MouseEvent ;  
  6.     import flash.geom.Matrix ;
  7.     /**
  8.     * 图片旋转
  9.     * @author luqinglong
  10.     */ 
  11.     public class ImageRotation extends Sprite{
  12.          
  13.           
  14.         private var _bitmap:Bitmap  ;
  15.           
  16.         private var _x:Number ;
  17.         private var _y:Number ;
  18.         private var _w:Number ;
  19.         private var _h:Number ; 
  20.            
  21.         //private var _angle:Number ;
  22.         public function ImageRotation() { 
  23.               
  24.             _bitmap = Main.SCENE.bitmap  ;
  25.             _x = _bitmap.x ;
  26.             _y = _bitmap.y ;   
  27.             _w = _bitmap.width  ;
  28.             _h = _bitmap.height ;
  29.             cancle_btn.addEventListener(MouseEvent.CLICK, cancleHandler);
  30.             
  31.             left_btn.addEventListener(MouseEvent.CLICK, leftRotationHandler);    
  32.             right_btn.addEventListener(MouseEvent.CLICK, rightRotationHandler) ;
  33.             save_btn.addEventListener(MouseEvent.CLICK, applicationHandler);
  34.               
  35.             //单击了旋转
  36.             Main._handerState = 10 ;
  37.             //go_cut_btn.addEventListener(MouseEvent.CLICK, goCutMenu);
  38.         }
  39.               
  40.         /*
  41.         private function goCutMenu(e:MouseEvent):void {
  42.             this.remove();     
  43.             Main.SCENE._imageCut.cutpicing();
  44.         }*/
  45.         
  46.         /**
  47.          * 取消操作
  48.          * @param   e
  49.          */
  50.         private function cancleHandler(e:MouseEvent):void {
  51.             //Main.SCENE.reset() ; 
  52.             Main._handerState = 0 ;
  53.             this.remove();  
  54.         }   
  55.               
  56.         public function remove():void {
  57.             Main.SCENE.bitmap.x = _x ;   
  58.             Main.SCENE.bitmap.y = _y ;            
  59.             Main.SCENE.bitmap.rotation = 0 ;
  60.             left_btn.removeEventListener(MouseEvent.CLICK, leftRotationHandler);
  61.             cancle_btn.removeEventListener(MouseEvent.CLICK, cancleHandler) ;
  62.             save_btn.removeEventListener(MouseEvent.CLICK, applicationHandler);
  63.             //go_cut_btn.removeEventListener(MouseEvent.CLICK, goCutMenu);
  64.                  
  65.             this.stage.removeChild(this) ;  
  66.         }
  67.         
  68.         private function applicationHandler(e:MouseEvent):void { 
  69.   
  70.             Main.SCENE.addVagueBg();    
  71.             Main.SCENE.addLoadingBar(); 
  72.                
  73.             var server :ImageService = new ImageService();
  74.             server.photoid = Main.SCENE.photoid ;      
  75.             server.submitRotation(fixAng( _bitmap.rotation) ); 
  76.     
  77.             left_btn.removeEventListener(MouseEvent.CLICK, leftRotationHandler);
  78.             cancle_btn.removeEventListener(MouseEvent.CLICK, cancleHandler) ;
  79.             save_btn.addEventListener(MouseEvent.CLICK, applicationHandler);
  80.             this.stage.removeChild(this) ;
  81.               
  82.             Main._handerState = 2  ;
  83.             
  84.         }
  85.       
  86.         /**
  87.          * 左旋转处理
  88.          * @param   e
  89.          */      
  90.         private function rightRotationHandler(e:MouseEvent):void {
  91.             var _angle = fixAng(_bitmap.rotation) ;
  92.              
  93.             if (_angle== 0) {    
  94.                 _bitmap.x = _x + (_h + _w) / 2 ;
  95.                 _bitmap.y = _y+(_h - _w) / 2 ;          
  96.                  
  97.             }                
  98.             else if (_angle == 90) {
  99.                 
  100.                 _bitmap.x = _x + _w ;    
  101.                 _bitmap.y = _y + _h ; 
  102.             }     
  103.             else if (_angle== 180) {
  104.                 _bitmap.x = _x - (_h - _w) / 2;               
  105.                 _bitmap.y = _y + (_w+_h)/2 ;
  106.               
  107.             }             
  108.             else if (_angle == 270) {   
  109.                 _bitmap.x = _x ;    
  110.                 _bitmap.y = _y;    
  111.                       
  112.             }
  113.                     
  114.             _bitmap.rotation += 90 ;   
  115.             _angle = fixAng( _bitmap.rotation) ;
  116.             trace("angle="+_angle);
  117.         }
  118.         private function leftRotationHandler(e:MouseEvent):void {
  119.      
  120.             var _angle = fixAng( _bitmap.rotation) ;
  121.             if (_angle == 0) {        
  122.                 _bitmap.x = _x - (_h - _w) / 2;               
  123.                 _bitmap.y = _y + (_w+_h)/2 ;    
  124.             }                 
  125.             else if (_angle == 270) {  
  126.                 _bitmap.x = _x + _w ;        
  127.                 _bitmap.y = _y + _h ;     
  128.             }                 
  129.             else if (_angle == 180 ){ 
  130.                 _bitmap.x = _x + (_h + _w) / 2 ;
  131.                 _bitmap.y = _y+(_h - _w) / 2 ;     
  132.                                          
  133.             }    
  134.             else if (_angle == 90) {   
  135.                 _bitmap.x = _x ;    
  136.                 _bitmap.y = _y;    
  137.             }            
  138.                    
  139.             _bitmap.rotation -= 90 ; 
  140.             trace("angle="+_angle);
  141.         }
  142.          
  143.         /**  
  144.          * 转换成标准角度
  145.          * @param   _ang
  146.          */
  147.         public static function fixAng (_ang:Number){
  148.             var _ang:Number = _ang % 360;
  149.             var ang:Number = _ang % 360 < 0 ? _ang + 360 : _ang;
  150.             return ang;
  151.         }
  152.         
  153.     }
  154.     
  155. }

代码四:

  1. package com.wdxc {
  2.     import com.wdxc.util.JPGEncoder;
  3.     import flash.events.Event;
  4.     import flash.net.URLLoader;
  5.     import flash.net.URLRequest; 
  6.     import flash.net.URLRequestMethod ;
  7.     import flash.net.URLVariables;
  8.       
  9.     /**
  10.     * 与服务端通信
  11.     * @author luqinglong
  12.     */
  13.     public class ImageService {   
  14.                  
  15.         private var url:String = "/photo/PhotoEditServlet" ;    
  16.         //private var url:String = "http://localhost:8080//photo/PhotoEditServlet" ;
  17.             
  18.          
  19.         private var _photoid:String ;
  20.         //?photoid=267005
  21.          
  22.         /**
  23.          * 照片id
  24.          */
  25.         public function set photoid(id:String):void {
  26.             this._photoid = id ;
  27.         }
  28.         public function get photoid():String {
  29.             return this._photoid ;
  30.         }
  31.         public function ImageService() {
  32.             
  33.         }
  34.           
  35.         /**
  36.          * 
  37.          * @param   type 判断是否裁剪或者旋转
  38.          * @param   photoid 照片id
  39.          * @param   x  
  40.          * @param   y
  41.          * @param   width
  42.          * @param   height
  43.          */   
  44.         public function submitCut(x:Number,y:Number,width:Number,height:Number,scale:String):void {
  45.             //url = url+"?"       
  46.             //url = url+"?radom="+Math.floor(Math.random()*1000)
  47.             var request:URLRequest = new URLRequest(url);  
  48.             var param:URLVariables = new URLVariables();      
  49.             param.random = Math.floor(Math.random() * 100);
  50.             param.photoid = _photoid ; 
  51.             param.type = Constant.OPERATE_CUT ;      
  52.             param.photoid = photoid ;     
  53.             param.scaleInfo = scale ;     
  54.             param.x = x ;
  55.             param.y = y ;
  56.             param.width = width ;
  57.             param.height = height ;
  58.             
  59.             request.data = param ;
  60.             
  61.                         
  62.             var loader:URLLoader = new URLLoader();    
  63.             //loader.
  64.                    
  65.             loader.load(request) ;  
  66.             loader.addEventListener(Event.COMPLETE, completeHandler) ;  
  67.             //loader.addEventListener(Event.)
  68.         }
  69.           
  70.         /**
  71.          * 保存旋转
  72.          * @param   ag
  73.          */
  74.         public function submitRotation(ag:Number):void {
  75.             var request:URLRequest = new URLRequest(url);  
  76.             var param:URLVariables = new URLVariables();          
  77.             param.random = Math.floor(Math.random() * 1000);
  78.             param.photoid = _photoid  ; 
  79.             param.type = Constant.OPERAT_ROTATION ;      
  80.             param.photoid = photoid ;
  81.             param.angle = ag ; 
  82.             request.data = param ;
  83.             
  84.                         
  85.             var loader:URLLoader = new URLLoader();    
  86.             //loader.
  87.               
  88.             loader.load(request) ;  
  89.             loader.addEventListener(Event.COMPLETE, completeHandler) ;  
  90.         
  91.         }
  92.               
  93.         /**  
  94.          * 对图片编码并提交给服务端保存。
  95.          * @param bitmapdata  
  96.          * @param url       
  97.          */          
  98.         /*
  99.         public function submit(bitmapdata:BitmapData, url:String):void {
  100.             
  101.             
  102.             var request:URLRequest = new URLRequest(url);  
  103.               
  104.             
  105.             var loader:URLLoader = new URLLoader();                  
  106.             loader.load(request) ;            
  107.                   
  108.             loader.addEventListener(Event.COMPLETE, completeHandler) ;  
  109.         }*/       
  110.                                         
  111.         private function completeHandler(e:Event):void {
  112.                
  113.             Main.SCENE.removeBitmap();    
  114.                  
  115.             Main.SCENE.startLoadPic();           
  116.             
  117.             e.currentTarget.removeEventListener(Event.COMPLETE, completeHandler);   
  118.         }  
  119.     }
  120.     
  121. }

 

代码五:

 

  1. package com.wdxc {
  2.     
  3.     /**
  4.     * ... 
  5.     * @author luqinglong
  6.     */
  7.     public class MouseInfo {
  8.         /*鼠标左边缘、右边缘等*/
  9.         private var _position:uint = 100 ;
  10.          
  11.         /*鼠标状态 按下、放开*/   
  12.         private var _state :uint = 100;  
  13.         
  14.         public function MouseInfo() {
  15.             
  16.         }
  17.           
  18.         public function set position(p:uint):void {
  19.             this._position = p ;
  20.         }
  21.         public function get position():uint {
  22.             return this._position ;
  23.         } 
  24.         
  25.         public function set state(s:uint):void {
  26.             this._state = s  ;
  27.         } 
  28.         public function get state():uint {
  29.             return _state ;
  30.         }
  31.              
  32.         /**  
  33.          * 是否满足对左边进行拖动拉伸的条件。
  34.          * @return boolean
  35.          */    
  36.         public function isStartLeftDrag():Boolean {
  37.             if (_position == Constant.LEFT && _state == Constant.MOUSE_DOWN) {
  38.                 return true ;
  39.             }
  40.             return false ;
  41.         }
  42.         
  43.         /**      
  44.          * 是否满足对右边界进行拖动拉伸的条件。
  45.          * @return boolean
  46.          */    
  47.         public function isStartRightDrag():Boolean {
  48.             if (_position == Constant.RIGHT && _state == Constant.MOUSE_DOWN) {
  49.                 return true ;
  50.             } 
  51.             return false ;
  52.         }
  53.         
  54.         /**      
  55.          * 是否满足对上边界进行拖动拉伸的条件。
  56.          * @return boolean
  57.          */        
  58.         public function isStartUpDrag():Boolean {
  59.             if (_position == Constant.UP && _state == Constant.MOUSE_DOWN) {
  60.                 return true ;
  61.             } 
  62.             return false ;   
  63.         }
  64.          
  65.         /**      
  66.          * 是否满足对下边界进行拖动拉伸的条件。
  67.          * @return boolean
  68.          */       
  69.         public function isStartDownDrag():Boolean {
  70.             if (_position == Constant.DOWN && _state == Constant.MOUSE_DOWN) {
  71.                 return true ;
  72.             } 
  73.             return false ;
  74.         }
  75.         /**       
  76.          * 是否满足对裁剪区域进行拖动拉伸的条件。
  77.          * @return boolean
  78.          */           
  79.         public function isStartMiddleDrag():Boolean {
  80.             if (_position == Constant.MIDDLE && _state == Constant.MOUSE_DOWN) {
  81.                 return true ;
  82.             } 
  83.             return false ;
  84.         }
  85.         /**        
  86.          * 是否满足对左上角拖动拉伸的条件。
  87.          * @return boolean
  88.          */           
  89.         public function isStratLeftUPDrag():Boolean {
  90.             if (_position == Constant.LEFT_UP && _state == Constant.MOUSE_DOWN) {
  91.                 return true ;
  92.             } 
  93.             return false ;
  94.         }   
  95.         /**         
  96.          * 是否满足对左下角拖动拉伸的条件。
  97.          * @return boolean
  98.          */            
  99.         public function isStratLeftDownDrag():Boolean {
  100.             if (_position == Constant.LEFT_DOWN && _state == Constant.MOUSE_DOWN) {
  101.                 return true ;
  102.             } 
  103.             return false ;
  104.         }   
  105.         /**        
  106.          * 是否满足对右上角拖动拉伸的条件。
  107.          * @return boolean
  108.          */            
  109.         public function isStratRightUPDrag():Boolean {
  110.             if (_position == Constant.RIGHT_UP && _state == Constant.MOUSE_DOWN) {
  111.                 return true ;
  112.             } 
  113.             return false ;
  114.         }   
  115.         /**         
  116.          * 是否满足对右下角拖动拉伸的条件。
  117.          * @return boolean
  118.          */            
  119.         public function isStratRightDownDrag():Boolean {
  120.             if (_position == Constant.RIGHT_DOWN && _state == Constant.MOUSE_DOWN) {
  121.                 return true ;
  122.             } 
  123.             return false ;
  124.         }           
  125.     } 
  126.     
  127. }

 

 

Top